[whatwg/fetch] Vague handling of Headers value for methods append and set (#1260)

While working on [undici-fetch](), a Node.js based implementation of Fetch, a developer discovered an issue where non string header values were throwing errors. Specifically, an array of strings `headers.append('key', ['val1', 'val2'])`. 

Based on the spec, values are first normalized:

> To normalize a potentialValue, remove any leading and trailing HTTP whitespace bytes from potentialValue.

Then, a TypeError should be thrown if value is not a value 

> A value is a byte sequence that matches the following conditions:
> Has no leading or trailing HTTP tab or space bytes.
> Contains no 0x00 (NUL) or HTTP newline bytes.

I assumed that values had to be strings.

But based on the behavior of the fetch api in Chrome and Firefox, it seems like the value is stringified and then normalized/validated. 

Can we update the spec to include this stringification step? And of course be specific about how we stringify the value?

We found some similar interesting behavior such as:

```
headers.append('key') // throws
headers.append('key', undefined) // fine undefined is stringified as 'undefined'
```

Related:
- https://github.com/Ethan-Arrowood/undici-fetch/pull/61
- https://github.com/Ethan-Arrowood/undici-fetch/issues/60

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

Received on Saturday, 26 June 2021 22:17:36 UTC