0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/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,
});
});
});