Skip to content

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

Closed
@jaylinski

Description

@jaylinski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions