Comments (2)
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.
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)
- Switch to built in http client (introduced in java 11) HOT 3
- Severe security vulnerability in used version of log4j2 HOT 2
- Skip query param encoding? HOT 3
- Parse-transit will ignore body is input-stream doesn't have data available right away HOT 2
- Async HTTP Request Connection Timeout Not Work Correctly HOT 3
- The word 'officially' is spelt wrong in the GitHub description HOT 1
- HEAD requests shouldn't discard body (in the request).
- Handling of private proxies HOT 2
- Whenever I get a 405 response from a server, a null pointer exception is thrown because the connection wasn't found HOT 1
- Nested query params
- cookie-policy none
- URL encoding of whitespace should be "%20" instead of "+" in query parameters HOT 1
- `:query-params` are re-ordered
- :threads is mis-named and mis-documented
- multipart posts: sending name requires a mime-type
- Async requests not really async
- AOT issues with clj_http.headers.HeaderMap HOT 4
- url path parameters HOT 2
- The :redirect-strategy doesn't seem to work for PUT and PATCH HTTP methods
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-http.