fix(download): ignore Content-Length when Content-Encoding is set#1857
Open
jlaportebot wants to merge 1 commit into
Open
fix(download): ignore Content-Length when Content-Encoding is set#1857jlaportebot wants to merge 1 commit into
jlaportebot wants to merge 1 commit into
Conversation
When a server returns Content-Encoding: gzip (or any non-identity encoding), requests/urllib3 transparently decompresses the response body. However, Content-Length reflects the compressed size per RFC 9110 §8.6. This mismatch caused HTTPie to flag complete downloads as "Incomplete download" because the decompressed bytes exceeded Content-Length. Fix by setting total_size to None when a non-identity Content-Encoding is present, preventing the size comparison that produces the false 'incomplete' error. This matches the behavior of curl and wget. Fixes httpie#1642 Also addresses httpie#423 (the existing FIXME comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a server returns
Content-Encoding: gzip(or any non-identity encoding), requests/urllib3 transparently decompresses the response body. However,Content-Lengthreflects the compressed size per RFC 9110 §8.6. This mismatch caused HTTPie to flag complete downloads as "Incomplete download" because the decompressed bytes exceededContent-Length.Example
Server returns:
HTTPie currently reports:
This is a false positive — the download is actually complete;
42846965is the decompressed size.Fix
Set
total_sizetoNonewhen a non-identityContent-Encodingis present, preventing the size comparison that produces the false "incomplete" error. This matches the behavior ofcurlandwget, which correctly trustContent-Lengthas the compressed size and simply save the file.Test Plan
test_download_with_content_encoding_gzip: verifies a download withContent-Encoding: gzipand decompressed body larger thanContent-Lengthis not flagged as incompletetest_download_with_content_encoding_identity_uses_content_length: verifiesContent-Encoding: identitystill usesContent-Lengthfor progresstest_download_with_content_encoding_gzip_interrupted: edge case testFixes #1642
Also addresses #423 (the existing FIXME comment about Content-Encoding: gzip)