| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0ab4614 commit 80c9ef0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar; | |||
| 33 | 33 | const outHeadersKey = require('internal/http').outHeadersKey; | |
| 34 | 34 | const async_id_symbol = process.binding('async_wrap').async_id_symbol; | |
| 35 | 35 | const nextTick = require('internal/process/next_tick').nextTick; | |
| 36 | + const errors = require('internal/errors'); | ||
| 36 | 37 | ||
| 37 | 38 | const CRLF = common.CRLF; | |
| 38 | 39 | const debug = common.debug; | |
@@ -427,6 +428,14 @@ function _storeHeader(firstLine, headers) { | |||
| 427 | 428 | } | |
| 428 | 429 | } | |
| 429 | 430 | ||
| 431 | + // Test non-chunked message does not have trailer header set, | ||
| 432 | + // message will be terminated by the first empty line after the | ||
| 433 | + // header fields, regardless of the header fields present in the | ||
| 434 | + // message, and thus cannot contain a message body or 'trailers'. | ||
| 435 | + if (this.chunkedEncoding !== true && state.trailer) { | ||
| 436 | + throw new errors.Error('ERR_HTTP_TRAILER_INVALID'); | ||
| 437 | + } | ||
| 438 | + | ||
| 430 | 439 | this._header = state.header + CRLF; | |
| 431 | 440 | this._headerSent = false; | |
| 432 | 441 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,6 +155,8 @@ E('ERR_PARSE_HISTORY_DATA', | |||
| 155 | 155 | (oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`); | |
| 156 | 156 | E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed'); | |
| 157 | 157 | E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed'); | |
| 158 | + E('ERR_HTTP_TRAILER_INVALID', | ||
| 159 | + 'Trailers are invalid with this transfer encoding'); | ||
| 158 | 160 | E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`); | |
| 159 | 161 | E('ERR_UNKNOWN_SIGNAL', (signal) => `Unknown signal: ${signal}`); | |
| 160 | 162 | E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // This test ensures that a Trailer header is set only when a chunked transfer | ||
| 5 | + // encoding is used. | ||
| 6 | + | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const http = require('http'); | ||
| 9 | + | ||
| 10 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 11 | + res.setHeader('Trailer', 'baz'); | ||
| 12 | + const trailerInvalidErr = { | ||
| 13 | + code: 'ERR_HTTP_TRAILER_INVALID', | ||
| 14 | + message: 'Trailers are invalid with this transfer encoding', | ||
| 15 | + type: Error | ||
| 16 | + }; | ||
| 17 | + assert.throws(() => res.writeHead(200, {'Content-Length': '2'}), | ||
| 18 | + common.expectsError(trailerInvalidErr)); | ||
| 19 | + res.removeHeader('Trailer'); | ||
| 20 | + res.end('ok'); | ||
| 21 | + })); | ||
| 22 | + server.listen(0, common.mustCall(() => { | ||
| 23 | + http.get({ port: server.address().port }, common.mustCall((res) => { | ||
| 24 | + assert.strictEqual(res.statusCode, 200); | ||
| 25 | + let buf = ''; | ||
| 26 | + res.on('data', (chunk) => { | ||
| 27 | + buf += chunk; | ||
| 28 | + }).on('end', common.mustCall(() => { | ||
| 29 | + assert.strictEqual(buf, 'ok'); | ||
| 30 | + })); | ||
| 31 | + server.close(); | ||
| 32 | + })); | ||
| 33 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments