Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2595fbc

Browse filesBrowse files
sagitsofanBridgeAR
authored andcommitted
http2: improve compatibility with http/1
When using the compatibility API the connection header is from now on ignored instead of throwing an `ERR_HTTP2_INVALID_CONNECTION_HEADERS` error. This logs a warning in such case to notify the user about the ignored header. PR-URL: #23908 Fixes: #23748 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent fc9ba36 commit 2595fbc
Copy full SHA for 2595fbc

File tree

Expand file treeCollapse file tree

2 files changed

+32
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/compat.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const {
4545
} = constants;
4646

4747
let statusMessageWarned = false;
48+
let statusConnectionHeaderWarned = false;
4849

4950
// Defines and implements an API compatibility layer on top of the core
5051
// HTTP/2 implementation, intended to provide an interface that is as
@@ -58,6 +59,8 @@ function assertValidHeader(name, value) {
5859
err = new ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED();
5960
} else if (value === undefined || value === null) {
6061
err = new ERR_HTTP2_INVALID_HEADER_VALUE(value, name);
62+
} else if (!isConnectionHeaderAllowed(name, value)) {
63+
connectionHeaderMessageWarn();
6164
}
6265
if (err !== undefined) {
6366
Error.captureStackTrace(err, assertValidHeader);
@@ -88,6 +91,23 @@ function statusMessageWarn() {
8891
}
8992
}
9093

94+
function isConnectionHeaderAllowed(name, value) {
95+
return name !== constants.HTTP2_HEADER_CONNECTION ||
96+
value === 'trailers';
97+
}
98+
99+
function connectionHeaderMessageWarn() {
100+
if (statusConnectionHeaderWarned === false) {
101+
process.emitWarning(
102+
'The provided connection header is not valid, ' +
103+
'the value will be dropped from the header and ' +
104+
'will never be in use.',
105+
'UnsupportedWarning'
106+
);
107+
statusConnectionHeaderWarned = true;
108+
}
109+
}
110+
91111
function onStreamData(chunk) {
92112
const request = this[kRequest];
93113
if (request !== undefined && !request.push(chunk))
@@ -539,6 +559,11 @@ class Http2ServerResponse extends Stream {
539559
[kSetHeader](name, value) {
540560
name = name.trim().toLowerCase();
541561
assertValidHeader(name, value);
562+
563+
if (!isConnectionHeaderAllowed(name, value)) {
564+
return;
565+
}
566+
542567
this[kHeaders][name] = value;
543568
}
544569

Collapse file

‎test/parallel/test-http2-server-set-header.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-server-set-header.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const body =
1111
const server = http2.createServer((req, res) => {
1212
res.setHeader('foobar', 'baz');
1313
res.setHeader('X-POWERED-BY', 'node-test');
14+
res.setHeader('connection', 'connection-test');
1415
res.end(body);
1516
});
1617

@@ -34,4 +35,10 @@ server.listen(0, common.mustCall(() => {
3435
req.end();
3536
}));
3637

38+
const compatMsg = 'The provided connection header is not valid, ' +
39+
'the value will be dropped from the header and ' +
40+
'will never be in use.';
41+
42+
common.expectWarning('UnsupportedWarning', compatMsg);
43+
3744
server.on('error', common.mustNotCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.