The Wayback Machine - http://web.archive.org/web/20201023140823/https://github.com/nodejs/node/issues/35658
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers with the same name are combined into one entry in `http2` #35658

Open
triblondon opened this issue Oct 15, 2020 · 3 comments
Open

Headers with the same name are combined into one entry in `http2` #35658

triblondon opened this issue Oct 15, 2020 · 3 comments
Labels

Comments

@triblondon
Copy link

@triblondon triblondon commented Oct 15, 2020

Version: 14.13.1
Platform: macOS, Darwin Kernel Version 19.6.0

What steps will reproduce the bug?

$ node
Welcome to Node.js v14.13.1.
Type ".help" for more information.
> (() => {
...   const http2 = require("http2");
...   const client = http2.connect("https://www.httpbin.org");
...   const req = client.request({ ":path": "/response-headers?foo=42&foo=43&foo=44" });
...   req.on("response", (headers, flags) => console.log("Response:", headers, flags));
...   req.on("end", () => client.close());
...   req.end();
... })();
undefined
> Response: [Object: null prototype] {
  ':status': 200,
  date: 'Thu, 15 Oct 2020 14:15:24 GMT',
  'content-type': 'application/json',
  'content-length': '117',
  server: 'gunicorn/19.9.0',
  foo: '42, 43, 44',
  'access-control-allow-origin': '*',
  'access-control-allow-credentials': 'true'
} 4

Versus cURL on the same URL:

$ curl -i "https://httpbin.org/response-headers?Foo=42&Foo=43&Foo=44"
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: 44
access-control-allow-origin: *
access-control-allow-credentials: true

...body...

How often does it reproduce? Is there a required condition?

Consistently reproducible

What is the expected behavior?

foo: ['42', '43', '44'],

Quoting the docs:

Headers are represented as own-properties on JavaScript objects. The property keys will be serialized to lower-case. Property values should be strings (if they are not they will be coerced to strings) or an Array of strings (in order to send more than one value per header field).

What do you see instead?

foo: '42, 43, 44',
@triblondon
Copy link
Author

@triblondon triblondon commented Oct 15, 2020

Of course I didn't read enough of the docs. Sigh.

For all other headers, the values are joined together with ', '.

I'd argue this is a bug anyway, because it seems Node can't allow me to distinguish between multiple response headers with the same name, and one header with comma-separated values. This behaviour is also inconsistent with the H1 implementation in Node, which does allow these headers to be identified separately.

But it is behaving as documented.

@watilde watilde added the http2 label Oct 16, 2020
@ZYSzys
Copy link
Member

@ZYSzys ZYSzys commented Oct 22, 2020

@triblondon It's intentional designed, looking at the rfc 7230 here:

A sender MUST NOT generate multiple header fields with the same field
name in a message unless either the entire field value for that
header field is defined as a comma-separated list [i.e., #(values)]
or the header field is a well-known exception (as noted below).

A recipient MAY combine multiple header fields with the same field
name into one "field-name: field-value" pair, without changing the
semantics of the message, by appending each subsequent field value to
the combined field value in order, separated by a comma.

@triblondon
Copy link
Author

@triblondon triblondon commented Oct 23, 2020

Being unable to see the wire format is somewhat limiting, though. My use case is a network instrumentation proxy, which is returning not quite accurate representations of the headers it received. And this is available in the h1 implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.