Skip to content

Fix #1642: Don't flag download as interrupted when Content-Encoding is set#1699

Open
rodionsteshenko wants to merge 1 commit intohttpie:masterfrom
rodionsteshenko:fix-issue-1642
Open

Fix #1642: Don't flag download as interrupted when Content-Encoding is set#1699
rodionsteshenko wants to merge 1 commit intohttpie:masterfrom
rodionsteshenko:fix-issue-1642

Conversation

@rodionsteshenko
Copy link

Problem

When downloading a response with Content-Encoding: gzip, httpie reports "Incomplete download" even though the download completed successfully. This happens because:

  1. Content-Length reflects the compressed size
  2. The requests library transparently decompresses the body
  3. The decompressed bytes are larger than Content-Length
  4. httpie compares them and flags the download as interrupted

Fix

When Content-Encoding is present in the response headers, skip using Content-Length for download progress/completeness tracking since the actual bytes written will be the decompressed size.

This also resolves the longstanding FIXME from #423.

Test

Added test_download_with_Content_Encoding_gzip_not_interrupted that:

  • Simulates a gzip-encoded response with Content-Length=100 but 500 bytes of decompressed data
  • Verifies the download is NOT flagged as interrupted
  • Fails without the fix (asserts downloader.interrupted is True)
  • Passes with the fix

Full test suite passes on macOS ARM (Apple Silicon), Python 3.12.

…ding is set

When Content-Encoding (e.g. gzip) is present, the requests library
transparently decompresses the response body. This means the actual
bytes written will be larger than Content-Length (which reflects the
compressed size). Previously, httpie would compare Content-Length against
the decompressed byte count and incorrectly flag the download as
'Incomplete'.

Fix: When Content-Encoding is set, skip Content-Length for progress
tracking since the sizes are inherently mismatched.

Also resolves the longstanding FIXME from httpie#423.

Added test: test_download_with_Content_Encoding_gzip_not_interrupted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments