Comments (5)
@shazow In the comment to release_conn
parameter to urlopen
method you wrote
This is useful if you're not preloading the response's content immediately.
It suggests we can't return connection to the pool before loading response's content but that's not the case, is it?
I guess the idea was to either release connection in HTTPConnectionPool.urlopen()
(if it's to be released automatically) or to pass it to HTTPResponse
(if it's not to be released automatically). Automatically releasing connection in HTTPResponse.read() goes against this idea by releasing connection which should not be released (that's why it was passed to HTTPResponse
). Removing code that releases connection in HTTPResponse.read()
makes all tests pass. What do you think?
from urllib3.
Alright I reinvestigated what I did when I wrote this and here's what's going on:
release_conn
only has an effect when preload_content=False
.
As you noticed, there's a convenience feature which automagically releases the connection once the full response has been read even when you specify release_conn=False
. To prevent this, you need to also specify preload_content=False
.
The reason for this is because we wanted to make preload_content=False
be default eventually (to promote on-demand loading which would make us perform better in benchmarks and generally more sane behaviour) and having release_conn
behave this way was a good way to set expectations for a future release without breaking backwards compatibility.
So here are the options:
- Remove this convenience feature and risk people forgetting to manually release the connection even after they've read the entire response. (Can we think of scenarios when we'd want to not release the connection even after we've read the entire response?)
- Document
release_conn
param more thoroughly to describe the dependency onpreload_content
. - Make
preload_content=False
default as planned in the next release.
I vote for 2 or 3.
from urllib3.
I'm not sure if I get this right.
The paramount question is this: is releasing a connection orthogonal to reading response's body? If it is I see no reason to make release_conn
depend on preload_content
.
Can we think of scenarios when we'd want to not release the connection even after we've read the entire response?
Yes, I think we should allow this. Someone, for instance, may want to do some request manually using such loose connection and then eventually return such connection to the pool.
The opposite situation is what I asked about here
It suggests we can't return connection to the pool before loading response's content but that's not the case, is it?
How about having 3 different states for release_conn
: immediately
, on_response_read
and never
?
from urllib3.
Oops, that last commit should have been issue 23, not 22. Disregard it.
from urllib3.
Looks like we've moved on from this.
from urllib3.
Related Issues (20)
- Provide a Test/Test-Mechanism for #3292 HOT 1
- Move response body handling into HTTP2Response HOT 3
- Add http_version property to BaseHTTPResponse HOT 4
- Ensure HTTP/2 isn't offered for tunnel CONNECT requests HOT 1
- Add HTTP/2 support for forwarding proxies HOT 2
- Add support for streaming HTTP/2 responses
- Allow HTTP/2 connection and socket to be re-used for future requests
- Add support for sending a request body with HTTP/2 HOT 1
- Add support for using HTTP/2 without TLS or prior knowledge HOT 1
- pypy tests often fail in CI with reason "cancelled after 30 minutes"
- Comply with TLS settings mandated for HTTP/2 in RFC 9113
- Upgrade mypy to the latest version in CI HOT 1
- Fix type checking when Zstandard is installed
- Move length_remaining into BaseHTTPResponse HOT 1
- Slow test cases on pypy3.9-7.3.15 on Ubuntu 22.04
- TLS 1.3 Post Handshake Auth no longer working with urllib 2.1.0 when ignoring cert validation HOT 1
- Create a workflow (nox?) for testing Emscripten support locally
- Emscripten support emits an InsecureRequestWarning even when using HTTPS
- Path toward testing with a released version of hypercorn? HOT 3
- Handle HTTP/2 informational responses (1xx) HOT 2
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 urllib3.