Bandaid fix for no content-length header.

This worked fine before and then I messed it up but I'm
not in the mood to go back and look at the old code.
This commit is contained in:
voussoir 2022-07-10 13:32:25 -07:00
parent c32f89da7d
commit 18de52ecb7
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -143,7 +143,8 @@ def download_plan(plan):
if plan.remote_total_bytes is None:
# Since we didn't do a head, let's fill this in now.
plan.remote_total_bytes = int(download_stream.headers.get('Content-Length', None))
plan.remote_total_bytes = download_stream.headers.get('Content-Length', None)
plan.remote_total_bytes = None if plan.remote_total_bytes is None else int(plan.remote_total_bytes)
progressbar = progressbars.normalize_progressbar(plan.progressbar, total=plan.remote_total_bytes)
@ -309,7 +310,8 @@ def prepare_plan(
# I'm using a GET instead of an actual HEAD here because some servers respond
# differently, even though they're not supposed to.
head = request('get', url, stream=True, headers=temp_headers, auth=auth)
remote_total_bytes = int(head.headers.get('content-length', None))
remote_total_bytes = head.headers.get('content-length', None)
remote_total_bytes = None if remote_total_bytes is None else int(remote_total_bytes)
server_respects_range = (head.status_code == 206 and 'content-range' in head.headers)
head.connection.close()
else: