Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
http2: add more connection specific headers
Browse files Browse the repository at this point in the history
These are forbidden by HTTP/2.

PR-URL: #128
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell committed May 31, 2017
1 parent f38a73a commit 79417fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ function getStreamState(session, stream) {
function isIllegalConnectionSpecificHeader(name, value) {
switch (name) {
case 'connection':
case 'upgrade':
case 'http2-settings':
case 'keep-alive':
case 'proxy-connection':
case 'transfer-encoding':
case 'upgrade':
return true;
case 'te':
return value !== 'trailers';
Expand All @@ -154,6 +157,7 @@ function mapToHeaders(map) {
var val;
if (typeof key === 'symbol' || value === undefined || !key)
continue;
key = String(key).toLowerCase();
var isArray = Array.isArray(value);
if (key[0] === ':') {
if (isArray) {
Expand Down
29 changes: 22 additions & 7 deletions test/parallel/test-http2-util-headers-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,27 @@ assert.throws(() => mapToHeaders({':path': [1, 2, 3]}),
message: /^HTTP\/2 pseudo-headers must have a single value$/
}));

['connection', 'upgrade', 'http2-settings', 'te'].forEach((i) => {
assert.throws(() => mapToHeaders({[i]: 'abc'}),
common.expectsError({
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
message: /^HTTP\/1 Connection specific headers are forbidden$/
}));
});
const regex =
/^HTTP\/1 Connection specific headers are forbidden$/;
['connection',
'upgrade',
'http2-settings',
'te',
'transfer-encoding',
'proxy-connection',
'keep-alive',
'Connection',
'Upgrade',
'HTTP2-Settings',
'TE',
'Transfer-Encoding',
'Proxy-Connection',
'Keep-Alive'].forEach((i) => {
assert.throws(() => mapToHeaders({[i]: 'abc'}),
common.expectsError({
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
message: regex
}), i);
});

assert.doesNotThrow(() => mapToHeaders({ te: 'trailers' }));

0 comments on commit 79417fe

Please sign in to comment.