Skip to content

Commit a1edb39

Browse files
fix(sdk-commands): avoid mutating immutable fetch response headers in auth proxy (#1440)
The `/auth` proxy in the linker dApp called `resp.headers.delete(...)` on a native-fetch (undici) Response. Those headers are guarded as immutable, so the delete threw `TypeError: immutable`, which surfaced as `Proxy error: immutable` and broke the login flow with a 500. Regression from the node-fetch -> native fetch migration in #1428. Build a filtered copy of the headers (skipping content-encoding / content-length) instead of deleting in place.
1 parent c65544e commit a1edb39

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • packages/@dcl/sdk-commands/src/linker-dapp

packages/@dcl/sdk-commands/src/linker-dapp/routes.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,22 @@ export function setRoutes<T extends { [key: string]: any }>(
7272

7373
// undici decompresses the body but leaves content-encoding / content-length in
7474
// place; forwarding them would make the client re-decode or truncate the body.
75-
resp.headers.delete('content-encoding')
76-
resp.headers.delete('content-length')
75+
// The headers on a fetch() Response are immutable (mutating them throws
76+
// `TypeError: immutable`), so build a filtered copy instead of deleting in place.
77+
const headers: Record<string, string> = {}
78+
for (const [key, value] of resp.headers) {
79+
const name = key.toLowerCase()
80+
if (name === 'content-encoding' || name === 'content-length') continue
81+
headers[key] = value
82+
}
7783

7884
// Return the proxied response, including body, status, and headers.
7985
// `resp.body` is a web ReadableStream; convert it to a Node stream so the
8086
// http-server can pipe it (it only handles Node streams / Buffers / strings).
8187
return {
8288
body: resp.body ? Readable.fromWeb(resp.body as any) : undefined,
8389
status: resp.status,
84-
headers: Object.fromEntries(resp.headers)
90+
headers
8591
}
8692
} catch (error) {
8793
return {

0 commit comments

Comments
 (0)