mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
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>
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
const server = http.createServer((req, res) => {
|
|
res.end('ok');
|
|
}).listen(0, common.mustCall(() => {
|
|
const agent = new http.Agent({
|
|
keepAlive: true,
|
|
maxSockets: 5,
|
|
maxFreeSockets: 2
|
|
});
|
|
|
|
const keepSocketAlive = agent.keepSocketAlive;
|
|
const reuseSocket = agent.reuseSocket;
|
|
|
|
let called = 0;
|
|
let expectedSocket;
|
|
agent.keepSocketAlive = common.mustCall((socket) => {
|
|
assert(socket);
|
|
|
|
called++;
|
|
if (called === 1) {
|
|
return false;
|
|
} else if (called === 2) {
|
|
expectedSocket = socket;
|
|
return keepSocketAlive.call(agent, socket);
|
|
}
|
|
|
|
assert.strictEqual(socket, expectedSocket);
|
|
return false;
|
|
}, 3);
|
|
|
|
agent.reuseSocket = common.mustCall((socket, req) => {
|
|
assert.strictEqual(socket, expectedSocket);
|
|
assert(req);
|
|
|
|
return reuseSocket.call(agent, socket, req);
|
|
}, 1);
|
|
|
|
function req(callback) {
|
|
http.request({
|
|
method: 'GET',
|
|
path: '/',
|
|
agent,
|
|
port: server.address().port
|
|
}, common.mustCall((res) => {
|
|
res.resume();
|
|
res.once('end', common.mustCall(() => {
|
|
setImmediate(callback);
|
|
}));
|
|
})).end();
|
|
}
|
|
|
|
// Should destroy socket instead of keeping it alive
|
|
req(common.mustCall(() => {
|
|
// Should keep socket alive
|
|
req(common.mustCall(() => {
|
|
// Should reuse the socket
|
|
req(common.mustCall(() => {
|
|
server.close();
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|