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

http2: fix mapToHeaders() with single string value #16458

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,14 @@ function mapToHeaders(map,
if (typeof key === 'symbol' || value === undefined || !key)
continue;
key = String(key).toLowerCase();
const isArray = Array.isArray(value);
let isArray = Array.isArray(value);
if (isArray) {
switch (value.length) {
case 0:
continue;
case 1:
value = String(value[0]);
isArray = false;
break;
default:
if (kSingleValueHeaders.has(key))
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-http2-util-headers-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ const {
);
}

{
// Arrays containing a single set-cookie value are handled correctly
// (issue #16452)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you please use the full URL: https://github.com/nodejs/node/issues/16452?

const headers = Object.create({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: just {} should be fine here.

headers['set-cookie'] = ['foo=bar'];
assert.deepStrictEqual(
mapToHeaders(headers),
[ [ 'set-cookie', 'foo=bar', '' ].join('\0'), 1 ]
);
}

// The following are not allowed to have multiple values
[
HTTP2_HEADER_STATUS,
Expand Down