Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move logic into compat.js
  • Loading branch information
sagitsofan committed Dec 14, 2018
commit 5c38e7d4c6eb8aa130b06d344265c73f109baa23
16 changes: 16 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
} = constants;

let statusMessageWarned = false;
const statusHeaderMessageWarned = {};

// Defines and implements an API compatibility layer on top of the core
// HTTP/2 implementation, intended to provide an interface that is as
Expand All @@ -60,6 +61,9 @@ function assertValidHeader(name, value) {
err = new ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED();
} else if (value === undefined || value === null) {
err = new ERR_HTTP2_INVALID_HEADER_VALUE(value, name);
} else if (name === constants.HTTP2_HEADER_CONNECTION) {
headerMessageWarn(name);
value = '';
}
if (err !== undefined) {
Error.captureStackTrace(err, assertValidHeader);
Expand Down Expand Up @@ -90,6 +94,18 @@ function statusMessageWarn() {
}
}

function headerMessageWarn(key) {
if (!statusHeaderMessageWarned[key] ||
statusHeaderMessageWarned[key] === false) {
process.emitWarning(
`The provided header "${key}" is not valid, ` +
'and is supported only for compatibility.',
'UnsupportedWarning'
);
statusHeaderMessageWarned[key] = true;
}
}

function onStreamData(chunk) {
const request = this[kRequest];
if (request !== undefined && !request.push(chunk))
Expand Down
11 changes: 1 addition & 10 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function getStreamState(stream) {

function isIllegalConnectionSpecificHeader(name, value) {
switch (name) {
case HTTP2_HEADER_CONNECTION:
case HTTP2_HEADER_UPGRADE:
case HTTP2_HEADER_HOST:
case HTTP2_HEADER_HTTP2_SETTINGS:
Expand Down Expand Up @@ -479,8 +480,6 @@ function mapToHeaders(map,
ret += `${key}\0${val}\0`;
}
count += value.length;
} else if (key === HTTP2_HEADER_CONNECTION) {
headerMessageWarn(key);
} else {
ret += `${key}\0${value}\0`;
count++;
Expand Down Expand Up @@ -586,14 +585,6 @@ function sessionName(type) {
}
}

function headerMessageWarn(key) {
process.emitWarning(
`The provided header "${key}" is not valid, ` +
'and is supported only for compatibility.',
'UnsupportedWarning'
);
}

module.exports = {
assertIsObject,
assertValidPseudoHeaderResponse,
Expand Down