Comments (2)
Thanks for the analysis! I was not aware of this.
requests currently documents a simple rule for using chunked transfer encoding: is the body an iterator? https://requests.kennethreitz.org/en/master/user/advanced/#chunk-encoded-requests
Of course the reality is much more complicated. The prepare_body
function decides on the headers, based on a number of factors (you've actually mentioned some of them), see https://github.com/psf/requests/blob/428f7a275914f60a8f1e76a7d69516d617433d30/requests/models.py#L453-L520
This makes sense for a higher-level API but we're not at this level yet, so for now I think we can look at the headers and if they're not there just perform a simple auto-detection to see if we have an iterator.
See urllib3/urllib3@3e586ef, we already look at existing headers, and already check if the body exists, so we only need to check if the body is an iterator to avoid chunking when it's not. requests uses this code:
is_stream = (
hasattr(data, '__iter__')
and not isinstance(data, (basestring, list, tuple, Mapping)))
And I guess that's enough for now? I don't think we want to provide the chunked
parameter, because advanced users can already specify this differently, and well, urllib3 has too many parameters!
We need to make sure that this plays well with retries: if the first request uses chunked encoding, then we should continue to do so with other requests. This is the bug in urllib3 that prompted urllib3#1715 and urllib#1734.
from hip.
I'd say the way Requests handles this is the proper technique and has worked well for them. I'll note here that I'd like to change how multipart forms are encoded so a typical use-case for them can rely on Content-Length instead of chunking.
from hip.
Related Issues (20)
- When should we run unasync? HOT 3
- Overall plans for the project HOT 9
- Test the Proactor event loop on Windows + Python 3.8 HOT 1
- Repo cleanup HOT 6
- More cleanups HOT 2
- Discussion: What do we call the async versions of hip.get, hip.post, etc.? HOT 24
- What should we do with urllib3's securetransport and pyopenssl support? HOT 1
- Early data support HOT 4
- Intermittent failures HOT 3
- Stop worrying about backwards-compatibility HOT 1
- support for request targets that can't be specified as URLs
- First steps towards a high-level HTTP client API
- Running unasync on test files HOT 8
- [API design] Streaming upload API: push-style or pull-style? HOT 3
- Tracking issue: intermittent test failures
- How to handle Response bodies?
- Improve documentation UX for sync and async APIs HOT 2
- Add support for Async and Sync Iterators as Request bodies
- ahip, hip, async tests and coverage HOT 3
- PoolManager(block=True) + trio.nursery causes EmptyPoolError HOT 3
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 hip.