node/test/parallel/test-http-req-res-close.js
Robert Nagy 28e6626ce7
http: set IncomingMessage.destroyed
IncomingMessage is a Readable stream and should properly
set the destroyed property.

PR-URL: https://github.com/nodejs/node/pull/33131
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2020-05-09 07:57:45 +02:00

38 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
const server = http.Server(common.mustCall((req, res) => {
let resClosed = false;
res.end();
let resFinished = false;
res.on('finish', common.mustCall(() => {
resFinished = true;
assert.strictEqual(resClosed, false);
assert.strictEqual(res.destroyed, false);
assert.strictEqual(resClosed, false);
}));
assert.strictEqual(req.destroyed, false);
res.on('close', common.mustCall(() => {
resClosed = true;
assert.strictEqual(resFinished, true);
assert.strictEqual(res.destroyed, true);
}));
assert.strictEqual(req.destroyed, false);
req.on('end', common.mustCall(() => {
assert.strictEqual(req.destroyed, false);
}));
req.on('close', common.mustCall(() => {
assert.strictEqual(req.destroyed, true);
assert.strictEqual(req._readableState.ended, true);
}));
res.socket.on('close', () => server.close());
}));
server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall());
}));