Giter VIP home page Giter VIP logo

Comments (2)

phronmophobic avatar phronmophobic commented on August 16, 2024

I dug into this a bit more. It seems that some requests will have their input stream wrapped with a ContentLengthInputStream.

Per their docs:

Note that this class NEVER closes the underlying stream, even when close gets called. Instead, it will read until the "end" of its limit on close, which allows for the seamless execution of subsequent HTTP 1.1 requests, while not requiring the client to remember to read the entire contents of the response.

What was happening is that calling .close on the inputstream would cause the ContentLengthInputStream to read the rest of the input (aka. downloading the rest of the input). The problem is that the example url is very large and takes quite a while to download. Testing with smaller downloads has shown that the .close will eventually complete after reading the full result.

It seems closing the body inputstream should terminate the connection rather than fully consuming the stream. Is this desired behavior?

A workaround is to call close on the http client before closing the stream, (.close (:http-client response)).

from clj-http.

phronmophobic avatar phronmophobic commented on August 16, 2024

Here's the workaround I ended up with so that closing the streams closes the connection.

(let [body
      (proxy [FilterInputStream]
          [^InputStream (:body response)]
          (close []
            (.close (:http-client response))))]
  (partially-consume body)
  (.close body))

from clj-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.