0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-server-de-chunked-trailer.js
Mithun Sasidharan acd4277134
test: replace assert.throws w/ common.expectsError
PR-URL: https://github.com/nodejs/node/pull/17497
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-12-08 13:37:33 -05:00

34 lines
993 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
};
common.expectsError(() => res.writeHead(200, { 'Content-Length': '2' }),
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();
}));
}));