Files
node/test/parallel/test-http-keepalive-free.js
Yagiz Nizipli 25c0c8e18a http: runtime deprecate instantiating without new
Promote DEP0195 from documentation-only to a runtime deprecation.
Calling node:http constructors without `new` now emits DEP0195 via
deprecateInstantiation. This covers Agent, Server, OutgoingMessage,
IncomingMessage, ServerResponse, and ClientRequest.

Update in-tree tests that called Server/Agent without `new` to use
the keyword, and add a dedicated DEP0195 coverage test.

Refs: https://github.com/nodejs/node/pull/58518
Assisted-by: Grok
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/64853
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-08-01 21:42:59 +00:00

37 lines
996 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 = new 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', common.mustCall(() => {
assert.strictEqual(req.destroyed, true);
req[method]();
assert.strictEqual(req.socket.destroyed, false);
agent.destroy();
server.close();
})).resume();
}))
.end();
assert.strictEqual(req.destroyed, false);
}));
}