google-cla[bot]: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fgoogle-resumable-media-python%2Fpull%2F170) for more info**.

<!-- need_sender_cla -->
google-cla[bot]: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fgoogle-resumable-media-python%2Fpull%2F170) for more info**.

<!-- need_sender_cla -->
crwilcox: Hi @mcsimps2 thank you for the contribution. Could I bother you to make a corresponding issue for this?
mcsimps2: @crwilcox It's mentioned in the summary at the bottom - it resolves #169.  I should've made it more clear that was the issue of concern, sorry about that!
crwilcox: @mcsimps2 Cool, I just missed it :)
crwilcox: Tests are reporting failed for linting, which is not your pr. I can create a separate PR and clean that up.
diff --git a/google/resumable_media/_helpers.py b/google/resumable_media/_helpers.py
index f57827e..3e4acf2 100644
--- a/google/resumable_media/_helpers.py
+++ b/google/resumable_media/_helpers.py
@@ -317,7 +317,8 @@ def _parse_checksum_header(header_value, response, checksum_label):
     matches = []
     for checksum in header_value.split(u","):
         name, value = checksum.split(u"=", 1)
-        if name == checksum_label:
+        # Official docs say "," is the separator, but real-world responses have encountered ", "
+        if name.lstrip() == checksum_label:
             matches.append(value)
 
     if len(matches) == 0:

Allow space in-between checksums in response headers
**Summary:** I encountered this bug when downloading files using the Google Cloud Storage Python libraries, but the bug is coming from the Resumable Media library.  The current code (and [official docs](https://cloud.google.com/storage/docs/xml-api/reference-headers#xgooghash)) assumes the checksum headers will be contiguous without whitespace:
```
'x-goog-hash': 'crc32c=t6zgHw==,md5=zH3E9XwJPGGra4vnT+aamQ=='
```
However, I'm actually getting responses with whitespaces between each type of checksum:
```
'x-goog-hash': 'crc32c=t6zgHw==, md5=zH3E9XwJPGGra4vnT+aamQ=='
```

Because of this, the checksum of downloaded files aren't being verified.

Solution is to patch `_helpers.py` as follows:
```
def _parse_checksum_header(header_value, response, checksum_label):
    if header_value is None:
        return None

    matches = []
    for checksum in header_value.split(u","):
        name, value = checksum.split(u"=", 1)
        # Use lstrip to support both "," and ", " as delimiters
        if name.lstrip() == checksum_label:
            matches.append(value)

    if len(matches) == 0:
        return None
    elif len(matches) == 1:
        return matches[0]
    else:
        raise common.InvalidResponse(
            response,
            u"X-Goog-Hash header had multiple ``{}`` values.".format(checksum_label),
            header_value,
            matches,
        )
```

Relevant: #22, #31, #32 
diff --git a/tests/unit/test__helpers.py b/tests/unit/test__helpers.py
index 7e1bb53..1297408 100644
--- a/tests/unit/test__helpers.py
+++ b/tests/unit/test__helpers.py
@@ -311,11 +311,12 @@ def test__DoNothingHash():
 
 
 class Test__get_expected_checksum(object):
+    @pytest.mark.parametrize("template", [u"crc32c={},md5={}", u"crc32c={}, md5={}"])
     @pytest.mark.parametrize("checksum", ["md5", "crc32c"])
     @mock.patch("google.resumable_media._helpers._LOGGER")
-    def test__w_header_present(self, _LOGGER, checksum):
+    def test__w_header_present(self, _LOGGER, template, checksum):
         checksums = {"md5": u"b2twdXNodGhpc2J1dHRvbg==", "crc32c": u"3q2+7w=="}
-        header_value = u"crc32c={},md5={}".format(checksums["crc32c"], checksums["md5"])
+        header_value = template.format(checksums["crc32c"], checksums["md5"])
         headers = {_helpers._HASH_HEADER: header_value}
         response = _mock_response(headers=headers)
 

pip install -e .[requests]
parse_log_pytest
pytest
pytest pytest-cov mock
3.8
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==7.6.1
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
google-crc32c==1.5.0
-e git+https://github.com/googleapis/google-resumable-media-python.git@cdea3eec76c7586a66b1641bca906f630d915c0e#egg=google_resumable_media
idna==3.10
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
mock==5.2.0
packaging @ file:///croot/packaging_1720101850331/work
pluggy @ file:///tmp/build/80754af9/pluggy_1648042571233/work
pytest @ file:///croot/pytest_1717793244625/work
pytest-cov==5.0.0
requests==2.32.3
six==1.17.0
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
urllib3==2.2.3

name: google-resumable-media-python
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py38h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.1=py38h06a4308_0
  - pip=24.2=py38h06a4308_0
  - pluggy=1.0.0=py38h06a4308_1
  - pytest=7.4.4=py38h06a4308_0
  - python=3.8.20=he870216_0
  - readline=8.2=h5eee18b_0
  - setuptools=75.1.0=py38h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py38h06a4308_0
  - wheel=0.44.0=py38h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==7.6.1
      - google-crc32c==1.5.0
      - idna==3.10
      - mock==5.2.0
      - pytest-cov==5.0.0
      - requests==2.32.3
      - six==1.17.0
      - urllib3==2.2.3
prefix: /opt/conda/envs/google-resumable-media-python

tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_present[md5-crc32c={},
tests/unit/test__helpers.py::test_do_nothing tests/unit/test__helpers.py::Test_header_required::test_success tests/unit/test__helpers.py::Test_header_required::test_success_with_callback tests/unit/test__helpers.py::Test_header_required::test_failure tests/unit/test__helpers.py::Test_header_required::test_failure_with_callback tests/unit/test__helpers.py::Test_require_status_code::test_success tests/unit/test__helpers.py::Test_require_status_code::test_success_with_callback tests/unit/test__helpers.py::Test_require_status_code::test_failure tests/unit/test__helpers.py::Test_require_status_code::test_failure_with_callback tests/unit/test__helpers.py::Test_calculate_retry_wait::test_past_limit tests/unit/test__helpers.py::Test_calculate_retry_wait::test_at_limit tests/unit/test__helpers.py::Test_calculate_retry_wait::test_under_limit tests/unit/test__helpers.py::Test_wait_and_retry::test_success_no_retry tests/unit/test__helpers.py::Test_wait_and_retry::test_success_with_retry tests/unit/test__helpers.py::Test_wait_and_retry::test_retry_exceeds_max_cumulative tests/unit/test__helpers.py::test__get_checksum_object[md5] tests/unit/test__helpers.py::test__get_checksum_object[crc32c] tests/unit/test__helpers.py::test__get_checksum_object[None] tests/unit/test__helpers.py::test__get_checksum_object_invalid tests/unit/test__helpers.py::test_crc32c_throws_import_error tests/unit/test__helpers.py::test_crc32c_warning_on_slow_crcmod tests/unit/test__helpers.py::test__DoNothingHash tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_present[md5-crc32c={},md5={}] tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_present[crc32c-crc32c={},md5={}] tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_present[crc32c-crc32c={}, tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_missing[md5] tests/unit/test__helpers.py::Test__get_expected_checksum::test__w_header_missing[crc32c] tests/unit/test__helpers.py::Test__parse_checksum_header::test_empty_value tests/unit/test__helpers.py::Test__parse_checksum_header::test_crc32c_only tests/unit/test__helpers.py::Test__parse_checksum_header::test_md5_only tests/unit/test__helpers.py::Test__parse_checksum_header::test_both_crc32c_and_md5 tests/unit/test__helpers.py::Test__parse_checksum_header::test_md5_multiple_matches
google/resumable_media/_helpers.py
google/resumable_media/_helpers.py