Skip to content

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

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

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

Conversation

@thiyaguk09

Copy link
Copy Markdown
Contributor

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 #7336

…t when json is present and header is missing
…tting content-type and skip test if Headers is undefined
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jun 3, 2026

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

Copy link
Copy Markdown
Contributor

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 adds logic to automatically set the 'Content-Type' header to 'application/json' when a JSON body is present in the request options, supporting both plain objects and Headers instances, and includes corresponding unit tests. The feedback suggests avoiding direct mutation of the user-provided headers object to prevent side-effects, recommending a shallow copy instead.

Comment thread handwritten/storage/src/nodejs-common/util.ts Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@thiyaguk09 thiyaguk09 marked this pull request as ready for review June 3, 2026 11:35
@thiyaguk09 thiyaguk09 requested a review from a team as a code owner June 3, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK sends incorrect Content-Type: text/plain with Impersonated ADC, causing "Parse Error" on metadata operations

1 participant