fix(storage): set application/json Content-Type for impersonated ADC requests#18
fix(storage): set application/json Content-Type for impersonated ADC requests#18thiyaguk09 wants to merge 3 commits into
Conversation
…t when json is present and header is missing
There was a problem hiding this comment.
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.
…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>
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 #<issue_number_goes_here> 🦕