Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning a native fetch()-response throws TypeError: immutable #10366

Closed
jaylinski opened this issue Jul 11, 2023 · 2 comments · Fixed by #10367
Closed

Returning a native fetch()-response throws TypeError: immutable #10366

jaylinski opened this issue Jul 11, 2023 · 2 comments · Fixed by #10367
Labels
bug Something isn't working

Comments

@jaylinski
Copy link
Contributor

jaylinski commented Jul 11, 2023

Describe the bug

According to the fetch()-specification, a header can have an immutable-guard which will throw a TypeError if the header is changed: https://fetch.spec.whatwg.org/#headers-class

When using fetch(), the spec requires the response header to be immutable (see step 12/4):
https://fetch.spec.whatwg.org/#fetch-method

This is implemented in undici (used by Node.js for native fetch() under the hood):
https://github.com/nodejs/undici/blob/22bdbd8c7820035276b4e876daccef513c29f5c4/lib/fetch/headers.js#L234-L239

The change introduced in #9993 will try to mutate the response header in certain scenarios, thus causing a TypeError.

Reproduction

A reproduction via failing test-case can be found in PR #10367.

Logs

No response

System Info

System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (6) arm64 unknown
    Memory: 11.31 GB / 15.61 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 20.2.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.6 - /usr/local/bin/npm

Severity

blocking an upgrade

Additional Information

This bug was caused by #9993.

@Conduitry
Copy link
Member

Another instance of this was fixed in #10030. This would presumably be fixed in a similar way.

@jaylinski
Copy link
Contributor Author

Another instance of this was fixed in #10030. This would presumably be fixed in a similar way.

Thanks, that's very helpful. I'll adapt my PR with a fix. :octocat:

@dummdidumm dummdidumm added the bug Something isn't working label Jul 12, 2023
dummdidumm pushed a commit that referenced this issue Jul 12, 2023
Fixes #10366, related to #10030.

According to the `fetch()`-specification, a header can have
an `immutable`-guard which will throw a `TypeError` if the
header is changed:
https://fetch.spec.whatwg.org/#headers-class

When using `fetch()`, the spec requires the response
header to be `immutable` (see step 12/4):
https://fetch.spec.whatwg.org/#fetch-method

This is implemented in undici (used by Node.js for native
fetch() under the hood):
https://github.com/nodejs/undici/blob/22bdbd8c7820035276b4e876daccef513c29f5c4/lib/fetch/headers.js#L234-L239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants