From fc8c574c07fd74d23f3ec70ee205dd2bba67141d Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Tue, 11 Aug 2026 13:09:00 +0000 Subject: [PATCH] fix: use lowercase x-goog-api-client header Use lowercase 'x-goog-api-client' header key to ensure compatibility with google-auth library's metric tracking. BUG=b/477154133 TAG=agy CONV=2f25336d-e8f9-413f-8292-73b7a55c1d81 --- packages/google-cloud-core/google/cloud/_http/__init__.py | 2 +- .../google-cloud-storage/google/cloud/storage/_helpers.py | 2 +- packages/google-cloud-storage/tests/unit/test_blob.py | 2 +- packages/google-cloud-storage/tests/unit/test_client.py | 4 ++-- .../google-cloud-storage/tests/unit/test_transfer_manager.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/google-cloud-core/google/cloud/_http/__init__.py b/packages/google-cloud-core/google/cloud/_http/__init__.py index af25e650db6e..43e482ef637b 100644 --- a/packages/google-cloud-core/google/cloud/_http/__init__.py +++ b/packages/google-cloud-core/google/cloud/_http/__init__.py @@ -34,7 +34,7 @@ DEFAULT_USER_AGENT = "gcloud-python/{0}".format(version.__version__) """The user agent for google-cloud-python requests.""" -CLIENT_INFO_HEADER = "X-Goog-API-Client" +CLIENT_INFO_HEADER = "x-goog-api-client" CLIENT_INFO_TEMPLATE = "gl-python/" + platform.python_version() + " gccl/{}" _USER_AGENT_ALL_CAPS_DEPRECATED = """\ diff --git a/packages/google-cloud-storage/google/cloud/storage/_helpers.py b/packages/google-cloud-storage/google/cloud/storage/_helpers.py index c5d2de61796b..4e9d435347d8 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_helpers.py +++ b/packages/google-cloud-storage/google/cloud/storage/_helpers.py @@ -767,7 +767,7 @@ def _get_default_headers( "Accept": "application/json", "Accept-Encoding": "gzip, deflate", "User-Agent": user_agent, - "X-Goog-API-Client": x_goog_api_client, + "x-goog-api-client": x_goog_api_client, "content-type": content_type, "x-upload-content-type": x_upload_content_type or content_type, } diff --git a/packages/google-cloud-storage/tests/unit/test_blob.py b/packages/google-cloud-storage/tests/unit/test_blob.py index ea08864b807b..c5609e3dd5c6 100644 --- a/packages/google-cloud-storage/tests/unit/test_blob.py +++ b/packages/google-cloud-storage/tests/unit/test_blob.py @@ -2688,7 +2688,7 @@ def test__get_upload_arguments(self): **custom_headers, } self.assertEqual( - headers["X-Goog-API-Client"], + headers["x-goog-api-client"], f"{client._connection.user_agent} {GCCL_INVOCATION_TEST_CONST} gccl-gcs-cmd/{COMMAND}", ) self.assertEqual(headers, expected_headers) diff --git a/packages/google-cloud-storage/tests/unit/test_client.py b/packages/google-cloud-storage/tests/unit/test_client.py index 61c7336f527c..9de5cf366688 100644 --- a/packages/google-cloud-storage/tests/unit/test_client.py +++ b/packages/google-cloud-storage/tests/unit/test_client.py @@ -2169,8 +2169,8 @@ def test_download_blob_have_different_uuid(self): client.download_blob_to_file(blob, file_obj) self.assertNotEqual( - blob._do_download.call_args_list[0][0][3]["X-Goog-API-Client"], - blob._do_download.call_args_list[1][0][3]["X-Goog-API-Client"], + blob._do_download.call_args_list[0][0][3]["x-goog-api-client"], + blob._do_download.call_args_list[1][0][3]["x-goog-api-client"], ) def test_list_blobs_w_defaults_w_bucket_obj(self): diff --git a/packages/google-cloud-storage/tests/unit/test_transfer_manager.py b/packages/google-cloud-storage/tests/unit/test_transfer_manager.py index 8c555de8b3fe..b9d6f11a742d 100644 --- a/packages/google-cloud-storage/tests/unit/test_transfer_manager.py +++ b/packages/google-cloud-storage/tests/unit/test_transfer_manager.py @@ -1218,7 +1218,7 @@ def test_upload_chunks_concurrently_with_metadata_and_encryption(): "Accept": "application/json", "Accept-Encoding": "gzip, deflate", "User-Agent": "agent", - "X-Goog-API-Client": f"agent gccl-invocation-id/{invocation_id} gccl-gcs-cmd/tm.upload_sharded", + "x-goog-api-client": f"agent gccl-invocation-id/{invocation_id} gccl-gcs-cmd/tm.upload_sharded", "content-type": FAKE_CONTENT_TYPE, "x-upload-content-type": FAKE_CONTENT_TYPE, "X-Goog-Encryption-Algorithm": "AES256",