GeezerVison is showing github.com — http2: pass incoming set-cookie header as array · nodejs/node@c88af23
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -2130,8 +2130,7 @@ For incoming headers: | 2130 | 2130 | `proxy-authorization`, `range`, `referer`,`retry-after`, `tk`, | 2131 | 2131 | `upgrade-insecure-requests`, `user-agent` or `x-content-type-options` are | 2132 | 2132 | 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. | 2135 | 2134 | * `cookie`: the values are joined together with '; '. | 2136 | 2135 | * For all other headers, the values are joined together with ', '. | 2137 | 2136 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/util.js +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -509,7 +509,7 @@ function toHeaderObject(headers) { | 509 | 509 | value |= 0; | 510 | 510 | var existing = obj[name]; | 511 | 511 | if (existing === undefined) { | 512 | | - obj[name] = value; | | 512 | + obj[name] = name === HTTP2_HEADER_SET_COOKIE ? [value] : value; | 513 | 513 | } else if (!kSingleValueHeaders.has(name)) { | 514 | 514 | switch (name) { | 515 | 515 | case HTTP2_HEADER_COOKIE: | @@ -528,10 +528,7 @@ function toHeaderObject(headers) { | 528 | 528 | // fields with the same name. Since it cannot be combined into a | 529 | 529 | // single field-value, recipients ought to handle "Set-Cookie" as a | 530 | 530 | // 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); | 535 | 532 | break; | 536 | 533 | default: | 537 | 534 | // https://tools.ietf.org/html/rfc7230#section-3.2.2 | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
| 1 | 1 | // Flags: --expose-internals | 2 | 2 | 'use strict'; | 3 | 3 |
| 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. | 6 | 6 |
| 7 | 7 | const common = require('../common'); | 8 | 8 | if (!common.hasCrypto) | 9 | 9 | common.skip('missing crypto'); | 10 | 10 | const assert = require('assert'); | 11 | | -const { mapToHeaders } = require('internal/http2/util'); | | 11 | +const { mapToHeaders, toHeaderObject } = require('internal/http2/util'); | 12 | 12 |
| 13 | 13 | const { | 14 | 14 | HTTP2_HEADER_STATUS, | @@ -305,3 +305,41 @@ common.expectsError({ | 305 | 305 |
| 306 | 306 | assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error)); | 307 | 307 | 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 | +} |
|