Skip to content

fix: preserve http headers supplied as Headers or tuples - #5404

Merged
jxom merged 2 commits into
mainfrom
jxom/http-headers-init
Nov 3, 2026
Merged

jxom merged 2 commits into
mainfrom
jxom/http-headers-init

Conversation

@jxom

@jxom jxom commented Nov 3, 2026

Copy link
Copy Markdown
Member

Fixes the http transport dropping fetchOptions.headers supplied as Headers instances or tuple arrays, and keeps init.headers a plain object so onFetchRequest hooks can spread it.

Supersedes #5390 (original commit by @mortezashojaei preserved).

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Error Error Nov 3, 2026 9:25pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T21:25:28.634741Z b0acafd PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f9d2529

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

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

@jxom
jxom force-pushed the jxom/http-headers-init branch from b0acafd to f9d2529 Compare November 3, 2026 21:20
@jxom
jxom merged commit 39d9b10 into main Nov 3, 2026
34 of 40 checks passed
@jxom
jxom deleted the jxom/http-headers-init branch November 3, 2026 21:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/utils/rpc/http.ts
Comment on lines +144 to +145
new Headers(init).forEach((value, key) => {
headers_[key] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/utils/rpc/http.ts
{ 'Content-Type': 'application/json' },
headers,
])
new Headers(init).forEach((value, key) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/utils/rpc/http.ts
Comment on lines +138 to +145
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/utils/rpc/http.ts
Comment on lines +144 to +145
new Headers(init).forEach((value, key) => {
headers_[key] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

jxom added a commit to wevm/ox that referenced this pull request Nov 8, 2026
…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]>
jxom added a commit to wevm/ox that referenced this pull request Nov 8, 2026
…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]>

This branch had an error being deployed

1 failed deployment
Preview — f9d25293 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants