GeezerVison is showing github.com — http2: preserve multiple content-encoding values · nodejs/node@4c9f878
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-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3679,7 +3679,7 @@ For incoming headers: | 3679 | 3679 | * The `:status` header is converted to `number`. | 3680 | 3680 | * Duplicates of `:status`, `:method`, `:authority`, `:scheme`, `:path`, | 3681 | 3681 | `:protocol`, `age`, `authorization`, `access-control-allow-credentials`, | 3682 | | - `access-control-max-age`, `access-control-request-method`, `content-encoding`, | | 3682 | + `access-control-max-age`, `access-control-request-method`, | 3683 | 3683 | `content-language`, `content-length`, `content-location`, `content-md5`, | 3684 | 3684 | `content-range`, `content-type`, `date`, `dnt`, `etag`, `expires`, `from`, | 3685 | 3685 | `host`, `if-match`, `if-modified-since`, `if-none-match`, `if-range`, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/util.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,6 @@ const { | 62 | 62 | HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD, | 63 | 63 | HTTP2_HEADER_AGE, | 64 | 64 | HTTP2_HEADER_AUTHORIZATION, | 65 | | - HTTP2_HEADER_CONTENT_ENCODING, | 66 | 65 | HTTP2_HEADER_CONTENT_LANGUAGE, | 67 | 66 | HTTP2_HEADER_CONTENT_LENGTH, | 68 | 67 | HTTP2_HEADER_CONTENT_LOCATION, | @@ -134,7 +133,6 @@ const kSingleValueFields = new SafeSet([ | 134 | 133 | HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD, | 135 | 134 | HTTP2_HEADER_AGE, | 136 | 135 | HTTP2_HEADER_AUTHORIZATION, | 137 | | - HTTP2_HEADER_CONTENT_ENCODING, | 138 | 136 | HTTP2_HEADER_CONTENT_LANGUAGE, | 139 | 137 | HTTP2_HEADER_CONTENT_LENGTH, | 140 | 138 | HTTP2_HEADER_CONTENT_LOCATION, | |
Collapse file Copy file name to clipboard +57Lines changed: 57 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +if (!common.hasCrypto) | | 5 | + common.skip('missing crypto'); | | 6 | +const assert = require('node:assert/strict'); | | 7 | +const http2 = require('node:http2'); | | 8 | +const { once } = require('node:events'); | | 9 | + | | 10 | +// Content-Encoding is a list (RFC 9110 section 8.4). Preserve all codings | | 11 | +// in their original order, regardless of single-value field validation. | | 12 | +async function test(options, value) { | | 13 | + const values = Array.isArray(value) ? value : [value]; | | 14 | + const expectedRaw = values.flatMap((v) => ['content-encoding', v]); | | 15 | + const expected = values.join(', '); | | 16 | + | | 17 | + function check(headers, rawHeaders) { | | 18 | + assert.strictEqual(headers['content-encoding'], expected); | | 19 | + const raw = []; | | 20 | + for (let i = 0; i < rawHeaders.length; i += 2) { | | 21 | + if (rawHeaders[i] === 'content-encoding') | | 22 | + raw.push(rawHeaders[i], rawHeaders[i + 1]); | | 23 | + } | | 24 | + assert.deepStrictEqual(raw, expectedRaw); | | 25 | + } | | 26 | + | | 27 | + const server = http2.createServer(options); | | 28 | + server.on('stream', common.mustCall((stream, headers, flags, rawHeaders) => { | | 29 | + check(headers, rawHeaders); | | 30 | + stream.respond({ 'content-encoding': value }); | | 31 | + stream.end(); | | 32 | + })); | | 33 | + server.listen(0); | | 34 | + await once(server, 'listening'); | | 35 | + | | 36 | + const client = http2.connect(`http://localhost:${server.address().port}`, options); | | 37 | + const req = client.request({ 'content-encoding': value }); | | 38 | + req.on('response', common.mustCall((headers, flags, rawHeaders) => { | | 39 | + check(headers, rawHeaders); | | 40 | + })); | | 41 | + req.resume(); | | 42 | + req.end(); | | 43 | + await once(req, 'end'); | | 44 | + client.close(); | | 45 | + await once(client, 'close'); | | 46 | + await new Promise((resolve) => server.close(resolve)); | | 47 | +} | | 48 | + | | 49 | +(async () => { | | 50 | + for (const options of [{}, { strictSingleValueFields: true }, | | 51 | + { strictSingleValueFields: false }]) { | | 52 | + for (const value of ['gzip', 'gzip, br', ['gzip', 'br'], | | 53 | + ['br', 'gzip'], ['gzip', 'gzip']]) { | | 54 | + await test(options, value); | | 55 | + } | | 56 | + } | | 57 | +})().then(common.mustCall()); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-util-headers-list.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -219,7 +219,6 @@ const { | 219 | 219 | HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD, | 220 | 220 | HTTP2_HEADER_AGE, | 221 | 221 | HTTP2_HEADER_AUTHORIZATION, | 222 | | - HTTP2_HEADER_CONTENT_ENCODING, | 223 | 222 | HTTP2_HEADER_CONTENT_LANGUAGE, | 224 | 223 | HTTP2_HEADER_CONTENT_LENGTH, | 225 | 224 | HTTP2_HEADER_CONTENT_LOCATION, | @@ -267,6 +266,7 @@ const { | 267 | 266 | }); | 268 | 267 |
| 269 | 268 | [ | | 269 | + HTTP2_HEADER_CONTENT_ENCODING, | 270 | 270 | HTTP2_HEADER_ACCEPT_CHARSET, | 271 | 271 | HTTP2_HEADER_ACCEPT_ENCODING, | 272 | 272 | HTTP2_HEADER_ACCEPT_LANGUAGE, | @@ -419,3 +419,10 @@ assert.strictEqual(getAuthority({ | 419 | 419 | assert.strictEqual(headers.age, '10'); | 420 | 420 | assert.strictEqual(headers['x-multi'], 'first, second'); | 421 | 421 | } | | 422 | + | | 423 | +// Content-Encoding is an ordered list, including repeated content codings. | | 424 | +for (const values of [['gzip', 'br'], ['br', 'gzip'], ['gzip', 'gzip']]) { | | 425 | + const rawHeaders = values.flatMap((value) => ['content-encoding', value]); | | 426 | + assert.strictEqual(toHeaderObject(rawHeaders)['content-encoding'], | | 427 | + values.join(', ')); | | 428 | +} |
|