| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fc9ba36 commit 2595fbc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ const { | |||
| 45 | 45 | } = constants; | |
| 46 | 46 | ||
| 47 | 47 | let statusMessageWarned = false; | |
| 48 | + let statusConnectionHeaderWarned = false; | ||
| 48 | 49 | ||
| 49 | 50 | // Defines and implements an API compatibility layer on top of the core | |
| 50 | 51 | // HTTP/2 implementation, intended to provide an interface that is as | |
@@ -58,6 +59,8 @@ function assertValidHeader(name, value) { | |||
| 58 | 59 | err = new ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED(); | |
| 59 | 60 | } else if (value === undefined || value === null) { | |
| 60 | 61 | err = new ERR_HTTP2_INVALID_HEADER_VALUE(value, name); | |
| 62 | + } else if (!isConnectionHeaderAllowed(name, value)) { | ||
| 63 | + connectionHeaderMessageWarn(); | ||
| 61 | 64 | } | |
| 62 | 65 | if (err !== undefined) { | |
| 63 | 66 | Error.captureStackTrace(err, assertValidHeader); | |
@@ -88,6 +91,23 @@ function statusMessageWarn() { | |||
| 88 | 91 | } | |
| 89 | 92 | } | |
| 90 | 93 | ||
| 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 | + | ||
| 91 | 111 | function onStreamData(chunk) { | |
| 92 | 112 | const request = this[kRequest]; | |
| 93 | 113 | if (request !== undefined && !request.push(chunk)) | |
@@ -539,6 +559,11 @@ class Http2ServerResponse extends Stream { | |||
| 539 | 559 | [kSetHeader](name, value) { | |
| 540 | 560 | name = name.trim().toLowerCase(); | |
| 541 | 561 | assertValidHeader(name, value); | |
| 562 | + | ||
| 563 | + if (!isConnectionHeaderAllowed(name, value)) { | ||
| 564 | + return; | ||
| 565 | + } | ||
| 566 | + | ||
| 542 | 567 | this[kHeaders][name] = value; | |
| 543 | 568 | } | |
| 544 | 569 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ const body = | |||
| 11 | 11 | const server = http2.createServer((req, res) => { | |
| 12 | 12 | res.setHeader('foobar', 'baz'); | |
| 13 | 13 | res.setHeader('X-POWERED-BY', 'node-test'); | |
| 14 | + res.setHeader('connection', 'connection-test'); | ||
| 14 | 15 | res.end(body); | |
| 15 | 16 | }); | |
| 16 | 17 | ||
@@ -34,4 +35,10 @@ server.listen(0, common.mustCall(() => { | |||
| 34 | 35 | req.end(); | |
| 35 | 36 | })); | |
| 36 | 37 | ||
| 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 | + | ||
| 37 | 44 | server.on('error', common.mustNotCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments