GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: preserve existing blob hashes when 'X-Goog-Hash header' is not present by MartinKilonzo · Pull Request #267 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.

fix: preserve existing blob hashes when 'X-Goog-Hash header' is not present #267

Merged
tseaver merged 5 commits into googleapis:master from MartinKilonzo:master
Sep 16, 2020

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix: preserve existing blob hashes when 'X-Goog-Hash header' is not present #267

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
4d3faad
fix(blob.py): returns blob hashes (md5, crc32c) when 'X-Goog-Hash hea…
remmykilonzo Sep 2, 2020
6250fcf
Renaming tests for downloads with missing headers to better reflect b…
remmykilonzo Sep 15, 2020
2e4f4dd
Only set CRC32C and MD5 hashes if they are present in the X-Goog-Hash…
remmykilonzo Sep 15, 2020
5f3586f
Merge branch 'master' into master
MartinKilonzo Sep 15, 2020
1b630d0
Merge branch 'master' into master
tseaver Sep 16, 2020
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

19 changes: 10 additions & 9 deletions 19 google/cloud/storage/blob.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,16 @@ def _extract_headers_from_download(self, response):
# 'X-Goog-Hash': 'crc32c=4gcgLQ==,md5=CS9tHYTtyFntzj7B9nkkJQ==',
x_goog_hash = response.headers.get("X-Goog-Hash", "")

digests = {}
for encoded_digest in x_goog_hash.split(","):
match = re.match(r"(crc32c|md5)=([\w\d/\+/]+={0,3})", encoded_digest)
if match:
method, digest = match.groups()
digests[method] = digest

self.crc32c = digests.get("crc32c", None)
self.md5_hash = digests.get("md5", None)
if x_goog_hash:
digests = {}
for encoded_digest in x_goog_hash.split(","):
match = re.match(r"(crc32c|md5)=([\w\d/\+/]+={0,3})", encoded_digest)
if match:
method, digest = match.groups()
digests[method] = digest

self.crc32c = digests.get("crc32c", None)
self.md5_hash = digests.get("md5", None)

def _do_download(
self,
Expand Down
12 changes: 9 additions & 3 deletions 12 tests/unit/test_blob.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,16 @@ def test_download_as_string_w_response_headers(self):

def test_download_as_string_w_hash_response_header_none(self):
Comment thread
MartinKilonzo marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

blob_name = "blob-name"
md5_hash = "CS9tHYTtyFntzj7B9nkkJQ=="
crc32c = "4gcgLQ=="
client = mock.Mock(spec=["_http"])
bucket = _Bucket(client)
media_link = "http://example.com/media/"
properties = {"mediaLink": media_link}
properties = {
"mediaLink": media_link,
"md5Hash": md5_hash,
"crc32c": crc32c,
}
blob = self._make_one(blob_name, bucket=bucket, properties=properties)

response = self._mock_requests_response(
Expand All @@ -1556,8 +1562,8 @@ def test_download_as_string_w_hash_response_header_none(self):
)
blob._extract_headers_from_download(response)

self.assertIsNone(blob.md5_hash)
self.assertIsNone(blob.crc32c)
self.assertEqual(blob.md5_hash, md5_hash)
self.assertEqual(blob.crc32c, crc32c)

def test_download_as_bytes_w_generation_match(self):
GENERATION_NUMBER = 6
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.