mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +00:00

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: https://github.com/nodejs/node/pull/12990 Ref: https://github.com/nodejs/node/issues/2842 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
34 lines
1000 B
JavaScript
34 lines
1000 B
JavaScript
'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();
|
|
}));
|
|
}));
|