Skip to content

Commit 17677bf

Browse files
http: join authorization headers
1 parent 28fe494 commit 17677bf

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

doc/api/cli.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ added: v12.3.0
456456

457457
Enable experimental WebAssembly module support.
458458

459+
### `--experimental-join-authorization-headers`
460+
461+
Enable experimental joining of the field line values of
462+
multiple `Authorization` headers in a request.
463+
459464
### `--force-context-aware`
460465

461466
<!-- YAML
@@ -1884,6 +1889,7 @@ Node.js options that are allowed are:
18841889
* `--experimental-vm-modules`
18851890
* `--experimental-wasi-unstable-preview1`
18861891
* `--experimental-wasm-modules`
1892+
* `--experimental-join-authorization-headers`
18871893
* `--force-context-aware`
18881894
* `--force-fips`
18891895
* `--force-node-api-uncaught-exceptions-policy`

lib/_http_incoming.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const {
3131
} = primordials;
3232

3333
const { Readable, finished } = require('stream');
34+
const { getOptionValue } = require('internal/options');
35+
36+
const joinAuthorizationHeaders = getOptionValue('--experimental-join-authorization-headers');
3437

3538
const kHeaders = Symbol('kHeaders');
3639
const kHeadersDistinct = Symbol('kHeadersDistinct');
@@ -400,6 +403,16 @@ function _addHeaderLine(field, value, dest) {
400403
} else {
401404
dest['set-cookie'] = [value];
402405
}
406+
} else if (joinAuthorizationHeaders && flag === 97) {
407+
// RFC 9110 https://www.rfc-editor.org/rfc/rfc9110#section-5.2
408+
// https://github.com/nodejs/node/issues/45699
409+
// allow authorization multiple fields
410+
// Make a delimited list
411+
if (typeof dest[field] === 'string') {
412+
dest[field] += ', ' + value;
413+
} else {
414+
dest[field] = value;
415+
}
403416
} else if (dest[field] === undefined) {
404417
// Drop duplicates
405418
dest[field] = value;

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
381381
"experimental ES Module support for webassembly modules",
382382
&EnvironmentOptions::experimental_wasm_modules,
383383
kAllowedInEnvvar);
384+
AddOption("--experimental-join-authorization-headers",
385+
"experimental joining of the field line values "
386+
"of multiple Authorization headers",
387+
&EnvironmentOptions::experimental_join_authorization_headers,
388+
kAllowedInEnvvar);
384389
AddOption("--experimental-import-meta-resolve",
385390
"experimental ES Module import.meta.resolve() support",
386391
&EnvironmentOptions::experimental_import_meta_resolve,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class EnvironmentOptions : public Options {
115115
bool experimental_global_web_crypto = true;
116116
bool experimental_https_modules = false;
117117
bool experimental_wasm_modules = false;
118+
bool experimental_join_authorization_headers = false;
118119
bool experimental_import_meta_resolve = false;
119120
std::string module_type;
120121
std::string experimental_policy;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Flags: --experimental-join-authorization-headers
2+
3+
'use strict';
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const http = require('http');
7+
8+
{
9+
const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => {
10+
assert.strictEqual(req.headers.authorization, '1, 2');
11+
res.writeHead(200, ['authorization', '3', 'authorization', '4']);
12+
res.end();
13+
}));
14+
15+
server.listen(0, common.mustCall(() => {
16+
http.get({ port: server.address().port, headers: ['authorization', '1', 'authorization', '2'] }, (res) => {
17+
assert.strictEqual(res.statusCode, 200);
18+
assert.strictEqual(res.headers.authorization, '3, 4');
19+
res.resume().on('end', common.mustCall(() => {
20+
server.close();
21+
}));
22+
});
23+
}));
24+
}

0 commit comments

Comments
 (0)