From 5c03176ae20c94f5f34456f10baeb2e258026899 Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Tue, 4 Oct 2022 17:13:56 +0200 Subject: [PATCH] fix: Do not validate checksums for partial responses --- google/_async_resumable_media/requests/download.py | 6 ++++-- google/resumable_media/requests/download.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/google/_async_resumable_media/requests/download.py b/google/_async_resumable_media/requests/download.py index 2b3e48ce..5b10e12e 100644 --- a/google/_async_resumable_media/requests/download.py +++ b/google/_async_resumable_media/requests/download.py @@ -90,7 +90,8 @@ async def _write_to_stream(self, response): self._stream.write(chunk) local_checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status != 206: actual_checksum = sync_helpers.prepare_checksum_digest( checksum_object.digest() ) @@ -213,7 +214,8 @@ async def _write_to_stream(self, response): self._stream.write(chunk) checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status != 206: actual_checksum = sync_helpers.prepare_checksum_digest( checksum_object.digest() ) diff --git a/google/resumable_media/requests/download.py b/google/resumable_media/requests/download.py index 88de223f..d202d56e 100644 --- a/google/resumable_media/requests/download.py +++ b/google/resumable_media/requests/download.py @@ -124,7 +124,8 @@ def _write_to_stream(self, response): self._bytes_downloaded += len(chunk) local_checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status_code != 206: actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest()) if actual_checksum != expected_checksum: msg = _CHECKSUM_MISMATCH.format( @@ -308,7 +309,8 @@ def _write_to_stream(self, response): checksum_object.update(chunk) response._content_consumed = True - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status_code != 206: actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest()) if actual_checksum != expected_checksum: