Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MediaIoBaseDownload range header off-by-one #1595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion googleapiclient/http.py
Expand Up @@ -733,7 +733,7 @@ def next_chunk(self, num_retries=0):
headers = self._headers.copy()
headers["range"] = "bytes=%d-%d" % (
self._progress,
self._progress + self._chunksize,
self._progress + self._chunksize - 1,
)
http = self._request.http

Expand Down
17 changes: 17 additions & 0 deletions tests/test_http.py
Expand Up @@ -488,6 +488,23 @@ def test_media_io_base_download(self):
self.assertEqual(5, download._progress)
self.assertEqual(5, download._total_size)

def test_media_io_base_download_range_request_header(self):
self.request.http = HttpMockSequence(
[
(
{"status": "200", "content-range": "0-2/5"},
"echo_request_headers_as_json",
),
]
)

download = MediaIoBaseDownload(fd=self.fd, request=self.request, chunksize=3)

status, done = download.next_chunk()
result = json.loads(self.fd.getvalue().decode("utf-8"))

self.assertEqual(result.get("range"), "bytes=0-2")

def test_media_io_base_download_custom_request_headers(self):
self.request.http = HttpMockSequence(
[
Expand Down