Skip to content

fix(storage): set application/json Content-Type for impersonated ADC requests#18

Open
thiyaguk09 wants to merge 3 commits into
mainfrom
fix/issue-7336-impersonated-adc-header
Open

fix(storage): set application/json Content-Type for impersonated ADC requests#18
thiyaguk09 wants to merge 3 commits into
mainfrom
fix/issue-7336-impersonated-adc-header

Conversation

@thiyaguk09
Copy link
Copy Markdown
Owner

Summary
This PR ensures that the Content-Type header is correctly set to application/json for metadata requests when using Application Default Credentials (ADC) with service account impersonation.

Problem
When the SDK is initialized with Impersonated ADC, certain metadata-only operations (like bucket.create()) were incorrectly sending a Content-Type: text/plain header. Because the request body contains a JSON payload, the Google Cloud Storage API would fail to parse the request and return a 400 Parse Error. This issue was specifically observed as a regression in version 7.17.3.

Fix
The decorateRequest method has been updated to check for the presence of a JSON payload. If a JSON body is present and no Content-Type header has been specified, the SDK now explicitly sets the header to application/json (source). This ensures that the GCS API can correctly interpret the request regardless of the authentication method being used.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

…t when json is present and header is missing
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates util.decorateRequest to automatically set the Content-Type header to application/json when a json payload is present, without overwriting any existing content-type header. It also adds unit tests to verify this behavior for both plain header objects and Headers instances. The review feedback suggests ensuring both .set and .has methods exist on the headers object to prevent runtime errors, and adding a guard in the tests for the global Headers class to maintain compatibility with older Node.js versions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread handwritten/storage/src/nodejs-common/util.ts Outdated
Comment thread handwritten/storage/test/nodejs-common/util.ts
thiyaguk09 and others added 2 commits June 3, 2026 09:21
…tting content-type and skip test if Headers is undefined
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant