You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--download reports an "incomplete download" with Content-Encoding: gzip and content-length. #423
When using HTTPie to download a file which is both gzip'd and has a content-length header sent, the final output report says that the download is incomplete. This is apparently because HTTPie tracks the number of bytes it wrote, not the number of bytes it received.
Here is an example, which reproduces in HTTPie head as of about 10 minutes ago.
$ http --debug --download GET http://torcache.net/torrent/640FE84C613C17F663551D218689A64E8AEBEABE.torrent
HTTPie 1.0.0-dev
HTTPie data: /Users/pi/.httpie
Requests 2.6.0
Pygments 2.0.2
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] darwin
>>> requests.request(**{'allow_redirects': True,
'auth': None,
'cert': None,
'data': OrderedDict(),
'files': DataDict(),
'headers': {'Accept-Encoding': None, 'User-Agent': 'HTTPie/1.0.0-dev'},
'method': u'get',
'params': ParamsDict(),
'proxies': {},
'stream': True,
'timeout': 30,
'url': u'http://torcache.net/torrent/640FE84C613C17F663551D218689A64E8AEBEABE.torrent',
'verify': True})
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: close
Content-Encoding: gzip
Content-Length: 40082
Content-Type: application/x-bittorrent
Date: Fri, 25 Dec 2015 04:39:03 GMT
ETag: "567c9773-9c92"
Last-Modified: Fri, 25 Dec 2015 01:10:11 GMT
Server: nginx
Downloading 39.14 kB to "640FE84C613C17F663551D218689A64E8AEBEABE.torrent"
- 0.00 % 0.00 B 0.00 B/s -:--:-- ETA
http: error: Incomplete download: size=40082; downloaded=40260
Done. 39.32 kB in 0.22557s (174.30 kB/s)
Note that size is the value of Content-length, but downloaded is greater than size because of the gzip encoding.
I think that fix is still vulnerable to a problem where the gzip content is incompletely downloaded, but still expands to greater than the content-length. I don't have a demonstration handy, though.
To me, it seems like Response.raw should be used; otherwise HTTPResponse.iter_body will return gzip -d'd chunks.
I think the output should be the decompressed output as it is now. It is just the warning that should go away. If the raw download matches what the http header said, all is good.
Make raw an opt-in for those cases when you really do not want the raw content encoding to be downloaded as-is. I think this issue should focus on getting rid of the error message by measuring the right thing.
Activity
fbidu commentedon Jan 30, 2016
Yeah, I could validate it here... I'll try to fix it
twopir commentedon Jan 30, 2016
I think that fix is still vulnerable to a problem where the gzip content is incompletely downloaded, but still expands to greater than the content-length. I don't have a demonstration handy, though.
fbidu commentedon Jan 30, 2016
hmm yeah, it could still be trouble... I'll try a better fix
jkbrzt commentedon Feb 28, 2016
https://github.com/jkbrzt/httpie/blob/2b51cb6687df037b94c901d5a3651296fd3cf07c/httpie/downloads.py#L181-L182
giuscri commentedon Mar 6, 2016
To me, it seems like
Response.rawshould be used; otherwiseHTTPResponse.iter_bodywill returngzip -d'd chunks.Add `Accept-Encoding: identity` for --download
hholst80 commentedon Oct 18, 2023
Greetings from 2023.
This is still an issue.
hholst80 commentedon Oct 18, 2023
I think the output should be the decompressed output as it is now. It is just the warning that should go away. If the raw download matches what the http header said, all is good.
Make raw an opt-in for those cases when you really do not want the raw content encoding to be downloaded as-is. I think this issue should focus on getting rid of the error message by measuring the right thing.
Ousret commentedon May 23, 2024
Decoded downloads: refactor, add decoded size notice, tests, etc.
Fix false "Incomplete download" error with Content-Encoding
Fix httpie#1642: Don't flag download as interrupted when Content-Enco…
Fix false 'Incomplete download' error when Content-Encoding is set