0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-http-parser-multiple-execute.js
Paolo Insogna b970634cfe http: defer reentrant execution of Parser::Execute
PR-URL: https://github.com/nodejs/node/pull/43369
Fixes: https://github.com/nodejs/node/issues/39671
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-06-22 10:55:18 +02:00

38 lines
824 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { request } = require('http');
const { Duplex } = require('stream');
let socket;
function createConnection(...args) {
socket = new Duplex({
read() {},
write(chunk, encoding, callback) {
if (chunk.toString().includes('\r\n\r\n')) {
this.push('HTTP/1.1 100 Continue\r\n\r\n');
}
callback();
}
});
return socket;
}
const req = request('http://localhost:8080', { createConnection });
req.on('information', common.mustCall(({ statusCode }) => {
assert.strictEqual(statusCode, 100);
socket.push('HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n');
socket.push(null);
}));
req.on('response', common.mustCall(({ statusCode }) => {
assert.strictEqual(statusCode, 200);
}));
req.end();