Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeid committed Jul 18, 2023
1 parent 5edf6b0 commit ea2d3f5
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions mozregression/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ def get_url(self):
"""
return self.__url

@staticmethod
def get_total_size(headers):
"""
Returns content length (integer) from response headers, if available.
:param headers: A :class:`requests.structures.CaseInsensitiveDict` object
representing response headers
"""
for header in ["content-length", "x-goog-stored-content-length"]:
if header in headers:
total_size = int(headers[header])
break
else:
total_size = 0
return total_size

def _update_progress(self, current, total):
with self._lock:
if self.__progress:
Expand All @@ -164,12 +180,7 @@ def _download(self, url, dest, finished_callback, chunk_size, session):
try:
with closing(session.get(url, stream=True)) as response:
# GCP storage does not always return a content-length header, check alternates.
for header in ["content-length", "x-goog-stored-content-length"]:
if header in response.headers:
total_size = int(response.headers[header])
break
else:
total_size = 0
total_size = self.get_total_size(response.headers)

if total_size:
self._update_progress(bytes_so_far, total_size)
Expand Down

0 comments on commit ea2d3f5

Please sign in to comment.