Skip to content

Commit

Permalink
Merge pull request #245 from mfschwartz/master
Browse files Browse the repository at this point in the history
Fix bug in handling chunked transfer-encoding downloads
  • Loading branch information
mfschwartz committed Oct 5, 2018
2 parents 8c50225 + c4afd9b commit 8e836fe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apitools/base/py/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ def __NormalizeStartEnd(self, start, end=None):
if end is not None:
if start < 0:
raise exceptions.TransferInvalidError(
'Cannot have end index with negative start index')
'Cannot have end index with negative start index ' +
'[start=%d, end=%d]' % (start, end))
elif start >= self.total_size:
raise exceptions.TransferInvalidError(
'Cannot have start index greater than total size')
'Cannot have start index greater than total size ' +
'[start=%d, total_size=%d]' % (start, self.total_size))
end = min(end, self.total_size - 1)
if end < start:
raise exceptions.TransferInvalidError(
Expand Down Expand Up @@ -481,6 +483,13 @@ def GetRange(self, start, end=None, additional_headers=None,
response = self.__ProcessResponse(response)
progress += response.length
if response.length == 0:
if response.status_code == http_client.OK:
# There can legitimately be no Content-Length header sent
# in some cases (e.g., when there's a Transfer-Encoding
# header) and if this was a 200 response (as opposed to
# 206 Partial Content) we know we're done now without
# looping further on received length.
return
raise exceptions.TransferRetryError(
'Zero bytes unexpectedly returned in download response')

Expand Down

0 comments on commit 8e836fe

Please sign in to comment.