fix(storage): set application/json Content-Type for impersonated ADC requests#8419
Open
thiyaguk09 wants to merge 4 commits into
Open
fix(storage): set application/json Content-Type for impersonated ADC requests#8419thiyaguk09 wants to merge 4 commits into
thiyaguk09 wants to merge 4 commits into
Conversation
…t when json is present and header is missing
…tting content-type and skip test if Headers is undefined
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR ensures that the
Content-Typeheader is correctly set toapplication/jsonfor 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 aContent-Type: text/plainheader. Because the request body contains a JSON payload, the Google Cloud Storage API would fail to parse the request and return a400 Parse Error. This issue was specifically observed as a regression in version 7.17.3.Fix
The
decorateRequestmethod has been updated to check for the presence of a JSON payload. If a JSON body is present and noContent-Typeheader has been specified, the SDK now explicitly sets the header toapplication/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:
Fixes #7336