Conversation
…nce, add default Content-Type for body requests - Add transformHeaders transformer that normalizes request.headers to a Headers instance (accepts plain objects and Headers instances) - Add transformHeaders as first entry in getDefaultTransformers pipeline - Set default Content-Type: application/json for body-bearing requests (non-GET/HEAD) when no Content-Type is already set in transformBody - Add changeset documenting all three breaking changes and migration steps - Add tests for Headers instance normalization, default Content-Type, and preservation of existing headers - Update website documentation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a breaking-change update to @merkur/plugin-http-client to standardize header handling by normalizing request.headers to a Headers instance, and to improve default request behavior by automatically applying Content-Type: application/json for body-bearing requests when not explicitly set.
Changes:
- Added a new built-in
transformHeaderstransformer and made it the first step in the default transformer pipeline. - Updated
transformBodyto auto-applyContent-Type: application/jsonfor non-GET/HEAD requests with a body when missing, and to use shared constants for JSON content-type matching. - Updated tests, documentation, and added a changeset with migration guidance for the breaking changes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
packages/plugin-http-client/src/index.js |
Adds transformHeaders and updates transformBody behavior around header normalization and default JSON Content-Type. |
packages/plugin-http-client/src/__tests__/indexSpec.js |
Adds coverage for header normalization and default Content-Type behavior; updates transformer pipeline expectations. |
packages/plugin-http-cache/src/__tests__/indexSpec.js |
Updates snapshot expectations to reflect the additional default transformer. |
packages/plugin-graphql-client/src/__tests__/indexSpec.js |
Updates snapshot expectations to reflect the additional default transformer. |
website/docs/http-client-plugin.md |
Documents Headers support, new default transformer order, and default Content-Type behavior. |
.changeset/http-client-headers-normalization.md |
Adds a major-version changeset explaining the breaking changes and migration steps. |
Suppressed comments (2)
website/docs/http-client-plugin.md:166
- The markdown table row for
headershas mismatched backticks, which breaks rendering (it currently showsobject \|Headers``).
| `headers` | `object \| `[Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers)`` | `{}` | Request headers — plain objects and `Headers` instances are both accepted |
.changeset/http-client-headers-normalization.md:65
- The polyfill note ties
Headersavailability to the bundler's ES target ("below ES2017"), but this is primarily a runtime-environment concern (whetherfetch/Headersexist), not a transpilation target. Rewording would avoid misleading migration guidance.
### Polyfill required for build targets below ES2017 (ES8)
The `Headers` global (part of the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Headers)) is used at runtime by `transformHeaders`. Widgets built with a bundler target below ES2017 (e.g. `target: 'es5'` or `target: 'es6'` in webpack/Rollup) that run in environments without a native `Headers` implementation must add a polyfill such as [`whatwg-fetch`](https://github.com/github/fetch) or [`cross-fetch`](https://github.com/lquixada/cross-fetch).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+207
to
211
| if (body && isBodyMethod) { | ||
| if (!newHeaders.has(CONTENT_TYPE_HEADER)) { | ||
| newHeaders.set(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON); | ||
| } | ||
|
|
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.
…nce, add default Content-Type for body requests