Skip to content

fix(rpc-provider): let fetch set UTF-8 content length - #6289

Open
snuff12 wants to merge 1 commit into
polkadot-js:masterfrom
snuff12:sn-http-utf8-content-length
Open

snuff12 wants to merge 1 commit into
polkadot-js:masterfrom
snuff12:sn-http-utf8-content-length

Conversation

@snuff12

@snuff12 snuff12 commented Nov 7, 2026

Copy link
Copy Markdown

Fixes #6288

HttpProvider set Content-Length to the JavaScript string length, which differs from the UTF-8 byte length for non-ASCII JSON. This can leave valid requests incomplete with Node's built-in fetch.

Remove the provider-generated header so fetch calculates the length of its string body. Explicit user headers, JSON encoding, and HTTP/RPC error handling remain unchanged.

Add 10 real localhost HTTP regression cases covering ASCII, Hangul, accents, surrogate pairs, combining characters, empty text, custom headers, an explicit correct length, HTTP errors, and RPC errors.

Validation:

  • node .yarn/releases/yarn-4.6.0.cjs test:one rpc-provider: runner reports 134 passed, 0 failed, 1 existing skipped suite, with both native fetch and NODE_OPTIONS=--no-experimental-fetch.
  • All 10 new cases pass. Against the original source, 7 fail and 3 pass, confirming regression sensitivity.
  • Full yarn build (including TypeScript project checks) and changed-file ESLint pass.
  • Built CJS/ESM HTTP consumers pass with both fetch implementations. Chrome 156 preserves exact Unicode echoes and byte lengths for both revisions.

The node-fetch fallback and browser paths already corrected/managed the header before this change. No live chain operations or full monorepo test run was used.

This branch has not been deployed

No deployments
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.

HttpProvider uses an incorrect Content-Length for Unicode JSON requests

1 participant