0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-parser-timeout-reset.js
Paolo Insogna 3caa2c1a00
http: refactor headersTimeout and requestTimeout logic
PR-URL: https://github.com/nodejs/node/pull/41263
Fixes: https://github.com/nodejs/node/issues/33440
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-04-13 15:47:59 +01:00

46 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const net = require('net');
const { HTTPParser } = process.binding('http_parser');
const server = net.createServer((socket) => {
socket.write('HTTP/1.1 200 OK\r\n');
socket.write('Transfer-Encoding: chunked\r\n\r\n');
setTimeout(() => {
socket.write('1\r\n');
socket.write('\n\r\n');
setTimeout(() => {
socket.write('1\r\n');
socket.write('\n\r\n');
setImmediate(() => {
socket.destroy();
server.close();
});
}, 500);
}, 500);
}).listen(0, () => {
const socket = net.connect(server.address().port);
const parser = new HTTPParser(HTTPParser.RESPONSE, false);
parser.initialize(
HTTPParser.RESPONSE,
{},
0,
0,
);
parser[HTTPParser.kOnTimeout] = common.mustNotCall();
parser[HTTPParser.kOnHeaders] = common.mustNotCall();
parser[HTTPParser.kOnExecute] = common.mustCallAtLeast(3);
parser[HTTPParser.kOnHeadersComplete] = common.mustCall();
parser[HTTPParser.kOnBody] = common.mustCall(2);
parser[HTTPParser.kOnMessageComplete] = common.mustNotCall();
parser.consume(socket._handle);
});