Repository navigation
fix: preserve http headers supplied as Headers or tuples - #5404
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦋 Changeset detectedLatest commit: f9d2529 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b0acafd to
f9d2529
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0acafd4fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| new Headers(init).forEach((value, key) => { | ||
| headers_[key] = value |
There was a problem hiding this comment.
Preserve header overrides across casing changes
When onFetchRequest returns a spread-based override using conventional casing, such as { ...init, headers: { ...init.headers, Authorization: 'Bearer ...' } }, this loop has already lowercased the existing key to authorization. Fetch then treats the two differently-cased object properties as duplicate headers and combines their values, producing values such as Basic ..., Bearer ... rather than replacing the original credential; the same problem affects attempts to override the default Content-Type. This breaks authenticated or custom-content-type requests whenever the hook uses different casing, so the plain-object conversion needs case-insensitive last-write-wins behavior.
Useful? React with 👍 / 👎.
| { 'Content-Type': 'application/json' }, | ||
| headers, | ||
| ]) | ||
| new Headers(init).forEach((value, key) => { |
There was a problem hiding this comment.
Avoid requiring global Headers with a custom fetch
In a runtime without built-in Fetch globals, such as Node 16 with node-fetch supplied through fetchFn, the custom function previously allowed requests to work because options.fetchFn ?? fetch does not evaluate the missing global fetch. The new unconditional new Headers(...) instead throws ReferenceError: Headers is not defined before that custom function runs, making fetchFn unusable as a fetch polyfill; the merge should not depend on a separate global implementation.
Useful? React with 👍 / 👎.
| const headers_: Record<string, string> = {} | ||
| for (const init of [ | ||
| headers_url, | ||
| { 'Content-Type': 'application/json' }, | ||
| headers, | ||
| ]) | ||
| new Headers(init).forEach((value, key) => { | ||
| headers_[key] = value |
There was a problem hiding this comment.
Store valid
__proto__ headers as own properties
When a Headers instance or tuple array contains the valid header name __proto__, assigning it into this ordinary {} invokes the inherited Object.prototype.__proto__ setter rather than creating an own property. The value consequently disappears from headers_ and is never sent, so the accumulator should use a null prototype or define entries as own properties.
Useful? React with 👍 / 👎.
| new Headers(init).forEach((value, key) => { | ||
| headers_[key] = value |
There was a problem hiding this comment.
Retain repeated
Set-Cookie header values
In Fetch implementations that expose separate Set-Cookie entries during Headers.forEach, including Node 24, this callback runs once for each value but each assignment replaces the preceding value. Supplying tuples such as [['Set-Cookie', 'a=1'], ['Set-Cookie', 'b=2']] therefore leaves only b=2 in the request, whereas passing the same HeadersInit directly to fetch retains both values; repeated entries need to be accumulated rather than overwritten within a single source.
Useful? React with 👍 / 👎.
…a`, `AbiItem`, `AbiEvent` and `RpcTransport` (#601) * fix: preserve odd-length hex bytes in sized Bytes.fromHex and Hex.toBytes Ports wevm/viem#5444. An odd-length value now gets its leading 0 before it is right-padded to size, so 0x1 with size 2 decodes to [1, 0] instead of [16, 0]. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: reject a short nonce and a version other than 1 in Siwe.validateMessage Ports wevm/viem#5440. EIP-4361 requires an alphanumeric nonce of at least 8 characters and version 1. Absent fields are still skipped. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: accept struct names that contain : in TypedData Ports wevm/viem#5403. Payloads such as HyperliquidTransaction:SendAsset failed TypedData.assert. The encoded type and hash are unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: resolve string overloads when the argument is not bytes Ports wevm/viem#5384. Dynamic bytes now matches only hex strings and Uint8Array values, so a plain string selects the string overload instead of throwing AbiItem.AmbiguityError. Hex strings still throw when both overloads match. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: match number and bigint integer arguments in AbiEvent Ports wevm/viem#5428. Integer arguments compare by value, so a number matches a decoded bigint and a bigint matches a small integer decoded as a number. A non-integer number still mismatches. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: merge RpcTransport.fromHttp headers through Headers Ports wevm/viem#5404. Default and caller headers are merged through Headers into a plain object, so a caller's Content-Type replaces the default whatever its casing, and Headers instances and tuple arrays keep their entries. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> --------- Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]>
…AbiItem`, `AbiEvent` and `RpcTransport` (#600) * fix: preserve odd-length hex bytes in sized Bytes.fromHex and Hex.toBytes Ports wevm/viem#5444. An odd-length value now gets its leading 0 before it is right-padded to size, so 0x1 with size 2 decodes to [1, 0] instead of [16, 0]. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: reject a short nonce and a version other than 1 in Siwe.validateMessage Ports wevm/viem#5440. EIP-4361 requires an alphanumeric nonce of at least 8 characters and version 1. Absent fields are still skipped. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: accept struct names that contain : in TypedData Ports wevm/viem#5403. Payloads such as HyperliquidTransaction:SendAsset failed TypedData.assert. The encoded type and hash are unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: resolve string overloads when the argument is not bytes Ports wevm/viem#5384. Dynamic bytes now matches only hex strings and Uint8Array values, so a plain string selects the string overload instead of throwing AbiItem.AmbiguityError. Hex strings still throw when both overloads match. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: match number and bigint integer arguments in AbiEvent Ports wevm/viem#5428. Integer arguments compare by value, so a number matches a decoded bigint and a bigint matches a small integer decoded as a number. A non-integer number still mismatches. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> * fix: merge RpcTransport.fromHttp headers through Headers Ports wevm/viem#5404. Default and caller headers are merged through Headers into a plain object, so a caller's Content-Type replaces the default whatever its casing, and Headers instances and tuple arrays keep their entries. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bcb4-18f0-70ab-84d3-47f6d9755544 Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]> --------- Co-authored-by: Amp <[email protected]> Co-authored-by: jxom <[email protected]>
Fixes the
httptransport droppingfetchOptions.headerssupplied asHeadersinstances or tuple arrays, and keepsinit.headersa plain object soonFetchRequesthooks can spread it.Supersedes #5390 (original commit by @mortezashojaei preserved).