0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-sync-write-error-during-continue.js
Austin Wright b32732b1ee
stream: expose DuplexPair API
PR-URL: https://github.com/nodejs/node/pull/34111
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-07-26 08:09:23 +00:00

54 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const { duplexPair } = require('stream');
// Regression test for the crash reported in
// https://github.com/nodejs/node/issues/15102 (httpParser.finish() is called
// during httpParser.execute()):
{
const [ clientSide, serverSide ] = duplexPair();
serverSide.on('data', common.mustCall((data) => {
assert.strictEqual(data.toString('utf8'), `\
GET / HTTP/1.1
Expect: 100-continue
Host: localhost:80
Connection: close
`.replace(/\n/g, '\r\n'));
setImmediate(() => {
serverSide.write('HTTP/1.1 100 Continue\r\n\r\n');
});
}));
const req = http.request({
createConnection: common.mustCall(() => clientSide),
headers: {
'Expect': '100-continue'
}
});
req.on('continue', common.mustCall((res) => {
let sync = true;
clientSide._writev = null;
clientSide._write = common.mustCall((chunk, enc, cb) => {
assert(sync);
// On affected versions of Node.js, the error would be emitted on `req`
// synchronously (i.e. before commit f663b31cc2aec), which would cause
// parser.finish() to be called while we are here in the 'continue'
// callback, which is inside a parser.execute() call.
assert.strictEqual(chunk.length, 4);
clientSide.destroy(new Error('sometimes the code just doesnt work'), cb);
});
req.on('error', common.mustCall());
req.end('data');
sync = false;
}));
}