GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: pass incoming set-cookie header as array · nodejs/node@c88af23

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • http2.md
  • lib/internal/http2
    • util.js
  • test/parallel
    • test-http2-util-headers-list.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/http2.md‎

Copy file name to clipboardExpand all lines: doc/api/http2.md
+1-2Lines changed: 1 addition & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2130,8 +2130,7 @@ For incoming headers:
21302130
`proxy-authorization`, `range`, `referer`,`retry-after`, `tk`,
21312131
`upgrade-insecure-requests`, `user-agent` or `x-content-type-options` are
21322132
discarded.
2133-
* `set-cookie` is a string if present once or an array in case duplicates
2134-
are present.
2133+
* `set-cookie` is always an array. Duplicates are added to the array.
21352134
* `cookie`: the values are joined together with '; '.
21362135
* For all other headers, the values are joined together with ', '.
21372136

Collapse file

‎lib/internal/http2/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/util.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function toHeaderObject(headers) {
509509
value |= 0;
510510
var existing = obj[name];
511511
if (existing === undefined) {
512-
obj[name] = value;
512+
obj[name] = name === HTTP2_HEADER_SET_COOKIE ? [value] : value;
513513
} else if (!kSingleValueHeaders.has(name)) {
514514
switch (name) {
515515
case HTTP2_HEADER_COOKIE:
@@ -528,10 +528,7 @@ function toHeaderObject(headers) {
528528
// fields with the same name. Since it cannot be combined into a
529529
// single field-value, recipients ought to handle "Set-Cookie" as a
530530
// special case while processing header fields."
531-
if (Array.isArray(existing))
532-
existing.push(value);
533-
else
534-
obj[name] = [existing, value];
531+
existing.push(value);
535532
break;
536533
default:
537534
// https://tools.ietf.org/html/rfc7230#section-3.2.2
Collapse file

‎test/parallel/test-http2-util-headers-list.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-util-headers-list.js
+41-3Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Flags: --expose-internals
22
'use strict';
33

4-
// Tests the internal utility function that is used to prepare headers
5-
// to pass to the internal binding layer.
4+
// Tests the internal utility functions that are used to prepare headers
5+
// to pass to the internal binding layer and to build a header object.
66

77
const common = require('../common');
88
if (!common.hasCrypto)
99
common.skip('missing crypto');
1010
const assert = require('assert');
11-
const { mapToHeaders } = require('internal/http2/util');
11+
const { mapToHeaders, toHeaderObject } = require('internal/http2/util');
1212

1313
const {
1414
HTTP2_HEADER_STATUS,
@@ -305,3 +305,41 @@ common.expectsError({
305305

306306
assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error));
307307
assert(!(mapToHeaders({ te: ['trailers'] }) instanceof Error));
308+
309+
310+
{
311+
const rawHeaders = [
312+
':status', '200',
313+
'cookie', 'foo',
314+
'set-cookie', 'sc1',
315+
'age', '10',
316+
'x-multi', 'first'
317+
];
318+
const headers = toHeaderObject(rawHeaders);
319+
assert.strictEqual(headers[':status'], 200);
320+
assert.strictEqual(headers.cookie, 'foo');
321+
assert.deepStrictEqual(headers['set-cookie'], ['sc1']);
322+
assert.strictEqual(headers.age, '10');
323+
assert.strictEqual(headers['x-multi'], 'first');
324+
}
325+
326+
{
327+
const rawHeaders = [
328+
':status', '200',
329+
':status', '400',
330+
'cookie', 'foo',
331+
'cookie', 'bar',
332+
'set-cookie', 'sc1',
333+
'set-cookie', 'sc2',
334+
'age', '10',
335+
'age', '20',
336+
'x-multi', 'first',
337+
'x-multi', 'second'
338+
];
339+
const headers = toHeaderObject(rawHeaders);
340+
assert.strictEqual(headers[':status'], 200);
341+
assert.strictEqual(headers.cookie, 'foo; bar');
342+
assert.deepStrictEqual(headers['set-cookie'], ['sc1', 'sc2']);
343+
assert.strictEqual(headers.age, '10');
344+
assert.strictEqual(headers['x-multi'], 'first, second');
345+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.