-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message body length not matching Content-Length should raise httplib.IncompleteRead even when using stream() #311
Comments
I'm open to a PR which changes this behaviour, but we need to be careful to take into account what @sigmavirus24 and @Lukasa said. Are you interested in submitting a patch for this, @patricklaw? |
Again, I have really mixed feelings about doing this on a |
Could add some kind of |
Why should you be prepared to accept more or less data than the server claims? And even if you should, why would you expect to not be informed as the spec instructs? |
@patricklaw What I'm getting at here is that it's totally reasonable to have a use case that says "I know that the server incorrectly indicated the length of the content, and I'm ok with that." There are plenty of reasons you might be OK with that: for instance, you might already know the server is faulty, or you might be testing a server you wrote that makes mistakes. When streaming data, in particular, the user of urllib3 is taking control of how data gets read away from urllib3. In effect, the user is saying "please let me choose how much data I read and when". In that world, the user doesn't need to be informed that they've downloaded more or less data than the server told them, because they should already know. I'd argue that if they don't know they should not be using the streaming API to begin with. There is added ambiguity in the spec caused by the phrase 'user-agent'. You believe (not necessarily incorrectly, by the way) that urllib3 is a user-agent. I believe that it needn't be a user-agent, and in fact whether it is depends entirely on the particular consumer of urllib3's APIs. For instance, it can be a lower-lying layer inside a higher-level user-agent (such as Requests, which also is sometimes not a user-agent). I'm entirely open to @shazow's suggestion of having a |
I followed up on this, because I was wondering why httplib wasn't raising this anyway. It turns out that With that in mind, I think we can close this and the associated requests issue. Everyone is doing the same thing here, and I think that thing is fine. |
I'm personally happy to leave this as-is too. @patricklaw If you still feel very strongly about it, I'm willing to review a PR for a |
If we are not throwing any exception for incomplete reads, what would be a way to catch such a case? In my case, I am streaming content 4kb at a time and I do not want to go ahead if the fetched content is incomplete. However, the status code is 200 and there is no way at all to find out if the content read is incomplete, as if chunk encoding is present, I do not even have content-length to compare against. |
If chunk encoding is present you should get errors if it is incomplete. |
More details in the issue I originally filed with requests (https://github.com/kennethreitz/requests/issues/1855). Here is a repro, slightly modified from the repro in that issue:
The text was updated successfully, but these errors were encountered: