Skip to content

Commit 2e4f4dd

Browse files
committed
Only set CRC32C and MD5 hashes if they are present in the X-Goog-Hash header.
1 parent 6250fcf commit 2e4f4dd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

google/cloud/storage/blob.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -811,15 +811,16 @@ def _extract_headers_from_download(self, response):
811811
# 'X-Goog-Hash': 'crc32c=4gcgLQ==,md5=CS9tHYTtyFntzj7B9nkkJQ==',
812812
x_goog_hash = response.headers.get("X-Goog-Hash", "")
813813

814-
digests = {}
815-
for encoded_digest in x_goog_hash.split(","):
816-
match = re.match(r"(crc32c|md5)=([\w\d/]+={0,3})", encoded_digest)
817-
if match:
818-
method, digest = match.groups()
819-
digests[method] = digest
820-
821-
self.crc32c = digests.get("crc32c", self.crc32c)
822-
self.md5_hash = digests.get("md5", self.md5_hash)
814+
if x_goog_hash:
815+
digests = {}
816+
for encoded_digest in x_goog_hash.split(","):
817+
match = re.match(r"(crc32c|md5)=([\w\d/\+/]+={0,3})", encoded_digest)
818+
if match:
819+
method, digest = match.groups()
820+
digests[method] = digest
821+
822+
self.crc32c = digests.get("crc32c", None)
823+
self.md5_hash = digests.get("md5", None)
823824

824825
def _do_download(
825826
self,

0 commit comments

Comments
 (0)