node/test/parallel/test-http-client-with-create-connection.js
theanarkh f63e8b7fa7
lib: fix http client socket path
PR-URL: https://github.com/nodejs/node/pull/51900
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-02-29 20:22:10 +00:00

56 lines
969 B
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
const net = require('net');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
let count = 0;
let server1;
let server2;
function request(options) {
count++;
http.get({
...options,
createConnection: (...args) => {
return net.connect(...args);
}
}, (res) => {
res.resume();
res.on('end', () => {
if (--count === 0) {
server1.close();
server2.close();
}
});
});
}
server1 = http.createServer((req, res) => {
res.end('ok');
}).listen(common.PIPE, () => {
server2 = http.createServer((req, res) => {
res.end('ok');
}).listen(() => {
request({
path: '/',
socketPath: common.PIPE,
});
request({
socketPath: common.PIPE,
});
request({
path: '/',
port: server2.address().port,
});
request({
port: server2.address().port,
});
});
});