grantila / fetch-h2

HTTP/1+2 Fetch API client for Node.js
MIT License
336 stars 16 forks source link

Headers with same name combine into one entry #112

Closed triblondon closed 2 years ago

triblondon commented 3 years ago

This HTTP request returns a response with multiple headers that have the same name:

$ curl -i "https://httpbin.org/response-headers?Foo=42&Foo=43&Foo=45"
HTTP/2 200 
date: Thu, 15 Oct 2020 12:58:56 GMT
content-type: application/json
content-length: 117
server: gunicorn/19.9.0
foo: 42
foo: 43
foo: 45
access-control-allow-origin: *
access-control-allow-credentials: true

...body...

However, the response returned by fetch-h2 combines these values into a comma-delimited string:

for (const h of response.headers.entries()) {
  if (h[0] === 'foo') console.log(h);
}

Outputs:

[ 'foo', '42, 43, 45' ]

When I would expect:

[ 'foo', ['42', '43', '45' ]]

This seems to be a NodeJS issue, and I've raised https://github.com/nodejs/node/issues/35658 over there.

grantila commented 2 years ago

I agree this could be useful, but as you write, this is from the node core itself, and not something fetch-h2 can mitigate, so closing