[downloader:http] fix issues with chunked transfer encoding
(fixes #1144)
This commit is contained in:
@@ -155,11 +155,15 @@ class HttpDownloader(DownloaderBase):
|
|||||||
size, self.maxsize)
|
size, self.maxsize)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
chunked = response.raw.chunked
|
||||||
|
content = response.iter_content(self.chunk_size)
|
||||||
|
|
||||||
# check filename extension against file header
|
# check filename extension against file header
|
||||||
if self.adjust_extension and not offset and \
|
if self.adjust_extension and not offset and \
|
||||||
pathfmt.extension in FILE_SIGNATURES:
|
pathfmt.extension in FILE_SIGNATURES:
|
||||||
try:
|
try:
|
||||||
file_header = next(response.iter_content(16), b"")
|
file_header = next(
|
||||||
|
content if chunked else response.iter_content(16), b"")
|
||||||
except (RequestException, SSLError, OpenSSLError) as exc:
|
except (RequestException, SSLError, OpenSSLError) as exc:
|
||||||
msg = str(exc)
|
msg = str(exc)
|
||||||
print()
|
print()
|
||||||
@@ -191,7 +195,7 @@ class HttpDownloader(DownloaderBase):
|
|||||||
|
|
||||||
self.out.start(pathfmt.path)
|
self.out.start(pathfmt.path)
|
||||||
try:
|
try:
|
||||||
self.receive(fp, response.iter_content(self.chunk_size))
|
self.receive(fp, content)
|
||||||
except (RequestException, SSLError, OpenSSLError) as exc:
|
except (RequestException, SSLError, OpenSSLError) as exc:
|
||||||
msg = str(exc)
|
msg = str(exc)
|
||||||
print()
|
print()
|
||||||
|
|||||||
Reference in New Issue
Block a user