mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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>
This commit is contained in:
1 parent
c08b797573
commit
f63e8b7fa7
2 files changed
+68
-5
No files matched your search
+13
-5
@@ -336,7 +336,16 @@ function ClientRequest(input, options, cb) {
|
||||
// No agent, default to Connection:close.
|
||||
this._last = true;
|
||||
this.shouldKeepAlive = false;
|
||||
if (typeof optsWithoutSignal.createConnection === 'function') {
|
||||
let opts = optsWithoutSignal;
|
||||
if (opts.path || opts.socketPath) {
|
||||
opts = { ...optsWithoutSignal };
|
||||
if (opts.socketPath) {
|
||||
opts.path = opts.socketPath;
|
||||
} else if (opts.path) {
|
||||
opts.path = undefined;
|
||||
}
|
||||
}
|
||||
if (typeof opts.createConnection === 'function') {
|
||||
const oncreate = once((err, socket) => {
|
||||
if (err) {
|
||||
process.nextTick(() => this.emit('error', err));
|
||||
@@ -346,8 +355,7 @@ function ClientRequest(input, options, cb) {
|
||||
});
|
||||
|
||||
try {
|
||||
const newSocket = optsWithoutSignal.createConnection(optsWithoutSignal,
|
||||
oncreate);
|
||||
const newSocket = opts.createConnection(opts, oncreate);
|
||||
if (newSocket) {
|
||||
oncreate(null, newSocket);
|
||||
}
|
||||
@@ -355,8 +363,8 @@ function ClientRequest(input, options, cb) {
|
||||
oncreate(err);
|
||||
}
|
||||
} else {
|
||||
debug('CLIENT use net.createConnection', optsWithoutSignal);
|
||||
this.onSocket(net.createConnection(optsWithoutSignal));
|
||||
debug('CLIENT use net.createConnection', opts);
|
||||
this.onSocket(net.createConnection(opts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
'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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user