2019-05-30 20:24:12 +02:00
|
|
|
// Flags: --expose-internals
|
|
|
|
|
2019-01-21 17:47:32 +11:00
|
|
|
'use strict';
|
2019-05-12 15:11:13 +08:00
|
|
|
const { expectsError, mustCall } = require('../common');
|
2019-01-21 17:47:32 +11:00
|
|
|
const assert = require('assert');
|
|
|
|
const { createServer, maxHeaderSize } = require('http');
|
|
|
|
const { createConnection } = require('net');
|
|
|
|
|
2019-05-30 20:24:12 +02:00
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
|
2019-01-21 17:47:32 +11:00
|
|
|
const CRLF = '\r\n';
|
|
|
|
const DUMMY_HEADER_NAME = 'Cookie: ';
|
|
|
|
const DUMMY_HEADER_VALUE = 'a'.repeat(
|
2019-03-07 01:03:53 +01:00
|
|
|
// Plus one is to make it 1 byte too big
|
2019-01-21 17:47:32 +11:00
|
|
|
maxHeaderSize - DUMMY_HEADER_NAME.length - (2 * CRLF.length) + 1
|
|
|
|
);
|
|
|
|
const PAYLOAD_GET = 'GET /blah HTTP/1.1';
|
|
|
|
const PAYLOAD = PAYLOAD_GET + CRLF +
|
|
|
|
DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE + CRLF.repeat(2);
|
|
|
|
|
|
|
|
const server = createServer();
|
|
|
|
|
|
|
|
server.on('connection', mustCall((socket) => {
|
2019-05-30 20:24:12 +02:00
|
|
|
// Legacy parser gives sligthly different response.
|
|
|
|
// This discripancy is not fixed on purpose.
|
|
|
|
const legacy = getOptionValue('--http-parser') === 'legacy';
|
2019-01-21 17:47:32 +11:00
|
|
|
socket.on('error', expectsError({
|
|
|
|
type: Error,
|
2019-07-01 00:34:55 +02:00
|
|
|
message: 'Parse Error: Header overflow',
|
2019-01-21 17:47:32 +11:00
|
|
|
code: 'HPE_HEADER_OVERFLOW',
|
2019-05-30 20:24:12 +02:00
|
|
|
bytesParsed: maxHeaderSize + PAYLOAD_GET.length - (legacy ? -1 : 0),
|
2019-01-21 17:47:32 +11:00
|
|
|
rawPacket: Buffer.from(PAYLOAD)
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
server.listen(0, mustCall(() => {
|
|
|
|
const c = createConnection(server.address().port);
|
|
|
|
let received = '';
|
|
|
|
|
|
|
|
c.on('connect', mustCall(() => {
|
|
|
|
c.write(PAYLOAD);
|
|
|
|
}));
|
|
|
|
c.on('data', mustCall((data) => {
|
|
|
|
received += data.toString();
|
|
|
|
}));
|
|
|
|
c.on('end', mustCall(() => {
|
|
|
|
assert.strictEqual(
|
|
|
|
received,
|
2019-03-06 12:07:47 +01:00
|
|
|
'HTTP/1.1 431 Request Header Fields Too Large\r\n' +
|
|
|
|
'Connection: close\r\n\r\n'
|
2019-01-21 17:47:32 +11:00
|
|
|
);
|
|
|
|
c.end();
|
|
|
|
}));
|
|
|
|
c.on('close', mustCall(() => server.close()));
|
|
|
|
}));
|