mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
b04e88439a
Calling destroy() on a completed ClientRequest, i.e. once 'close' will be emitted should be a noop. Also before emitting 'close' destroyed === true. Fixes: https://github.com/nodejs/node/issues/32851 PR-URL: https://github.com/nodejs/node/pull/33120 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
37 lines
975 B
JavaScript
37 lines
975 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
for (const method of ['abort', 'destroy']) {
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end(req.url);
|
|
}));
|
|
server.listen(0, common.mustCall(() => {
|
|
const agent = http.Agent({ keepAlive: true });
|
|
|
|
const req = http
|
|
.request({
|
|
port: server.address().port,
|
|
agent
|
|
})
|
|
.on('socket', common.mustCall((socket) => {
|
|
socket.on('free', common.mustCall());
|
|
}))
|
|
.on('response', common.mustCall((res) => {
|
|
assert.strictEqual(req.destroyed, false);
|
|
res.on('end', () => {
|
|
assert.strictEqual(req.destroyed, true);
|
|
req[method]();
|
|
assert.strictEqual(req.socket.destroyed, false);
|
|
agent.destroy();
|
|
server.close();
|
|
}).resume();
|
|
}))
|
|
.end();
|
|
assert.strictEqual(req.destroyed, false);
|
|
}));
|
|
}
|