From 79417fe59332bc6a46ac07c6b88275eb3c1b7a8e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 16 May 2017 12:21:09 -0700 Subject: [PATCH] http2: add more connection specific headers These are forbidden by HTTP/2. PR-URL: https://github.com/nodejs/http2/pull/128 Reviewed-By: Matteo Collina --- lib/internal/http2/util.js | 6 +++- test/parallel/test-http2-util-headers-list.js | 29 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index fe8542e24f..9441f3e461 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -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'; @@ -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) { diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js index 8799353e99..c86c72ec65 100644 --- a/test/parallel/test-http2-util-headers-list.js +++ b/test/parallel/test-http2-util-headers-list.js @@ -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' }));