Skip to content

Commit 1edbc7d

Browse files
theanarkhmarco-ippolito
authored andcommitted
lib: fix http client socket path
PR-URL: #51900 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 014cc53 commit 1edbc7d

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

‎lib/_http_client.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,16 @@ function ClientRequest(input, options, cb) {
336336
// No agent, default to Connection:close.
337337
this._last=true;
338338
this.shouldKeepAlive=false;
339-
if(typeofoptsWithoutSignal.createConnection==='function'){
339+
letopts=optsWithoutSignal;
340+
if(opts.path||opts.socketPath){
341+
opts={ ...optsWithoutSignal};
342+
if(opts.socketPath){
343+
opts.path=opts.socketPath;
344+
}elseif(opts.path){
345+
opts.path=undefined;
346+
}
347+
}
348+
if(typeofopts.createConnection==='function'){
340349
constoncreate=once((err,socket)=>{
341350
if(err){
342351
process.nextTick(()=>this.emit('error',err));
@@ -346,17 +355,16 @@ function ClientRequest(input, options, cb) {
346355
});
347356

348357
try{
349-
constnewSocket=optsWithoutSignal.createConnection(optsWithoutSignal,
350-
oncreate);
358+
constnewSocket=opts.createConnection(opts,oncreate);
351359
if(newSocket){
352360
oncreate(null,newSocket);
353361
}
354362
}catch(err){
355363
oncreate(err);
356364
}
357365
}else{
358-
debug('CLIENT use net.createConnection',optsWithoutSignal);
359-
this.onSocket(net.createConnection(optsWithoutSignal));
366+
debug('CLIENT use net.createConnection',opts);
367+
this.onSocket(net.createConnection(opts));
360368
}
361369
}
362370
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
consthttp=require('http');
4+
constnet=require('net');
5+
consttmpdir=require('../common/tmpdir');
6+
7+
tmpdir.refresh();
8+
9+
letcount=0;
10+
letserver1;
11+
letserver2;
12+
13+
functionrequest(options){
14+
count++;
15+
http.get({
16+
...options,
17+
createConnection: (...args)=>{
18+
returnnet.connect(...args);
19+
}
20+
},(res)=>{
21+
res.resume();
22+
res.on('end',()=>{
23+
if(--count===0){
24+
server1.close();
25+
server2.close();
26+
}
27+
});
28+
});
29+
}
30+
31+
server1=http.createServer((req,res)=>{
32+
res.end('ok');
33+
}).listen(common.PIPE,()=>{
34+
server2=http.createServer((req,res)=>{
35+
res.end('ok');
36+
}).listen(()=>{
37+
request({
38+
path: '/',
39+
socketPath: common.PIPE,
40+
});
41+
42+
request({
43+
socketPath: common.PIPE,
44+
});
45+
46+
request({
47+
path: '/',
48+
port: server2.address().port,
49+
});
50+
51+
request({
52+
port: server2.address().port,
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)