-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: edit _storeHeader to check for Trailer header
Test non-chunked message does not have trailer header set, message will be terminated by the first empty line after the header fields, regardless of the header fields present in the message, and thus cannot contain a message body or 'trailers'. PR-URL: #12990 Ref: #2842 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
- Loading branch information
1 parent
0ab4614
commit 80c9ef0
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This test ensures that a Trailer header is set only when a chunked transfer | ||
// encoding is used. | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
res.setHeader('Trailer', 'baz'); | ||
const trailerInvalidErr = { | ||
code: 'ERR_HTTP_TRAILER_INVALID', | ||
message: 'Trailers are invalid with this transfer encoding', | ||
type: Error | ||
}; | ||
assert.throws(() => res.writeHead(200, {'Content-Length': '2'}), | ||
common.expectsError(trailerInvalidErr)); | ||
res.removeHeader('Trailer'); | ||
res.end('ok'); | ||
})); | ||
server.listen(0, common.mustCall(() => { | ||
http.get({ port: server.address().port }, common.mustCall((res) => { | ||
assert.strictEqual(res.statusCode, 200); | ||
let buf = ''; | ||
res.on('data', (chunk) => { | ||
buf += chunk; | ||
}).on('end', common.mustCall(() => { | ||
assert.strictEqual(buf, 'ok'); | ||
})); | ||
server.close(); | ||
})); | ||
})); |