Skip to content

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

Merged
Dhriti07 merged 11 commits into
googleapis:mainfrom
thiyaguk09:fix/issue-7336-impersonated-adc-header
Jun 22, 2026
Merged

fix(storage): set application/json Content-Type for impersonated ADC requests#8419
Dhriti07 merged 11 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
@Dhriti07
Dhriti07 merged commit 292c688 into googleapis:main Jun 22, 2026
33 checks passed
@thiyaguk09
thiyaguk09 deleted the fix/issue-7336-impersonated-adc-header branch June 30, 2026 07:59
shivanee-p pushed a commit that referenced this pull request Aug 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.22.0](storage-v7.21.0...storage-v7.22.0)
(2026-08-11)


### Features

* **storage:** Add deleteSourceObjects option to combine/compose method
([#8444](#8444))
([43abc45](43abc45))


### Bug Fixes

* **storage:** Destroy local read stream on upload write failure to
prevent resource leaks
([#8752](#8752))
([77dab53](77dab53)),
refs
[#7325](#7325)
* **storage:** Pass signingEndpoint to URLSigner in file.getSignedUrl
([#8982](#8982))
([b001807](b001807))
* **storage:** Resolve Node compatibility crashes, security
vulnerability, and stream hangs
([#8622](#8622))
([512ba79](512ba79))
* **storage:** Set application/json Content-Type for impersonated ADC
requests
([#8419](#8419))
([292c688](292c688))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
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

2 participants