[whatwg/fetch] Behavior of `Headers.set(name, null)` and `Headers.get(name)` (Issue #1792)

### What is the issue with the Fetch Standard?

Currently, when `name` is absent from an Headers, the behavior of `Headers.get(name)` doesn't seem to be stated in the [standard](https://fetch.spec.whatwg.org/#ref-for-dom-headers-set%E2%91%A0):

> Returns as a string the values of all headers whose name is name, separated by a comma and a space.

Currently, it seems to be implemented as returning `null` if the header doesn't exist.

However,  in some places (Deno, Firefox, Chromium), `Headers.set(name, null)` seems to be implemented as creating a `name` headers with the value `"null"`, i.e. converting  `null` into a `string`.

This breaks the  `get`/`set` symmetry: indeed, we should be able to do  `Headers.set(name, Headers.get(name))`.

The standard states:

> Replaces the value of the first header whose name is name with value and removes any remaining headers whose name is name.

I think something like "if value is null, all headers are removed" should be added to the documentation to remove such faulty behavior.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1792
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1792@github.com>

Received on Saturday, 7 December 2024 19:38:45 UTC