mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
91020db933
PR-URL: https://github.com/nodejs/node/pull/44378 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
|
|
// TODO(@jasnell) At some point this should be refactored as the API should not
|
|
// be allowing users to set multiple content-length values in the first place.
|
|
|
|
function test(server) {
|
|
server.listen(0, common.mustCall(() => {
|
|
http.get(
|
|
{ port: server.address().port },
|
|
() => { assert.fail('Client allowed multiple content-length headers.'); }
|
|
).on('error', common.mustCall((err) => {
|
|
assert.ok(err.message.startsWith('Parse Error'), err.message);
|
|
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
|
server.close();
|
|
}));
|
|
}));
|
|
}
|
|
|
|
// Test adding an extra content-length header using setHeader().
|
|
{
|
|
const server = http.createServer((req, res) => {
|
|
res.setHeader('content-length', [2, 1]);
|
|
res.end('k');
|
|
});
|
|
|
|
test(server);
|
|
}
|
|
|
|
// Test adding an extra content-length header using writeHead().
|
|
{
|
|
const server = http.createServer((req, res) => {
|
|
res.writeHead(200, { 'content-length': [1, 2] });
|
|
res.end('ok');
|
|
});
|
|
|
|
test(server);
|
|
}
|