From 9e45790c7c972a54e0dafbcd0ed49b2a35bd2bee Mon Sep 17 00:00:00 2001 From: pfurpass Date: Fri, 13 Mar 2026 21:55:00 +0100 Subject: [PATCH] Fix false 'Incomplete download' error when Content-Encoding is set When a server sends Content-Encoding (e.g. gzip), the requests library decompresses the body transparently. This causes the number of downloaded bytes to exceed Content-Length (which reflects the compressed size), triggering a false 'Incomplete download' error. Fix: skip Content-Length size validation when Content-Encoding is present. Fixes #1642 Closes #1554 Refs #423 --- httpie/downloads.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/httpie/downloads.py b/httpie/downloads.py index 9c4b895e6f..ffa0a8b8c0 100644 --- a/httpie/downloads.py +++ b/httpie/downloads.py @@ -216,10 +216,15 @@ def start( """ assert not self.status.time_started - # FIXME: some servers still might sent Content-Encoding: gzip - # + # Don't use Content-Length for size validation when Content-Encoding + # is present (e.g. gzip), because requests decompresses the body + # transparently, making downloaded bytes > Content-Length. + # See: https://github.com/httpie/cli/issues/1642 try: - total_size = int(final_response.headers['Content-Length']) + if 'Content-Encoding' in final_response.headers: + total_size = None + else: + total_size = int(final_response.headers['Content-Length']) except (KeyError, ValueError, TypeError): total_size = None