ardatan/whatwg-node

Header name must be a valid HTTP token

GauBen opened this issue · 3 comments

GauBen commented

Hey! Latest version of @whatwg-node/server contains a runtime error:

TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["[ 'content-type', 'application/json; charset=utf-8' ]"]

It happens at these lines

https://github.com/ardatan/whatwg-node/blob/ac9ff01410984eec256d6addea503fad28b03c3e/packages/server/src/utils.ts#L191C2-L193

This is because

headers may be an Array where the keys and values are in the same list. It is not a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. The array is in the same format as request.rawHeaders.

-- https://nodejs.org/api/http.html#responsewriteheadstatuscode-statusmessage-headers

This can be fixed using [...fetchResponse.headers].flat()

Yeah broo, i just found it out and i did something like Object.fromEntries(fetchResponse.headers.map.entries()). Anyway, please fix this ASAP, as grapqhlYoga depends on it :(

@Ranjanlc Maybe you can collaborate this free and open source project ASAP? :D

Fixed in 928d70e