mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 19:25:07 +00:00

Added .destroyed property to OutgoingMessage and ClientRequest to align with streams. Fixed ClientRequest.destroy to dump res and re-use socket in agent pool aligning it with abort. PR-URL: https://github.com/nodejs/node/pull/32148 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
|
|
{
|
|
// abort
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end('Hello');
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const options = { port: server.address().port };
|
|
const req = http.get(options, common.mustCall((res) => {
|
|
res.on('data', (data) => {
|
|
req.abort();
|
|
assert.strictEqual(req.aborted, true);
|
|
assert.strictEqual(req.destroyed, true);
|
|
server.close();
|
|
});
|
|
}));
|
|
req.on('error', common.mustNotCall());
|
|
assert.strictEqual(req.aborted, false);
|
|
assert.strictEqual(req.destroyed, false);
|
|
}));
|
|
}
|
|
|
|
{
|
|
// destroy + res
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end('Hello');
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const options = { port: server.address().port };
|
|
const req = http.get(options, common.mustCall((res) => {
|
|
res.on('data', (data) => {
|
|
req.destroy();
|
|
assert.strictEqual(req.aborted, false);
|
|
assert.strictEqual(req.destroyed, true);
|
|
server.close();
|
|
});
|
|
}));
|
|
req.on('error', common.mustNotCall());
|
|
assert.strictEqual(req.aborted, false);
|
|
assert.strictEqual(req.destroyed, false);
|
|
}));
|
|
}
|
|
|
|
{
|
|
// destroy
|
|
|
|
const server = http.createServer(common.mustNotCall((req, res) => {
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const options = { port: server.address().port };
|
|
const req = http.get(options, common.mustNotCall());
|
|
req.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
|
server.close();
|
|
}));
|
|
assert.strictEqual(req.aborted, false);
|
|
assert.strictEqual(req.destroyed, false);
|
|
req.destroy();
|
|
assert.strictEqual(req.aborted, false);
|
|
assert.strictEqual(req.destroyed, true);
|
|
}));
|
|
}
|