Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1edbc7d

Browse filesBrowse 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
Copy full SHA for 1edbc7d

File tree

Expand file treeCollapse file tree

2 files changed

+68
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+68
-5
lines changed
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+13-5Lines 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 (typeof optsWithoutSignal.createConnection === 'function') {
339+
let opts = optsWithoutSignal;
340+
if (opts.path || opts.socketPath) {
341+
opts = { ...optsWithoutSignal };
342+
if (opts.socketPath) {
343+
opts.path = opts.socketPath;
344+
} else if (opts.path) {
345+
opts.path = undefined;
346+
}
347+
}
348+
if (typeof opts.createConnection === 'function') {
340349
const oncreate = 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-
const newSocket = optsWithoutSignal.createConnection(optsWithoutSignal,
350-
oncreate);
358+
const newSocket = 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
}
Collapse file
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
const common = require('../common');
3+
const http = require('http');
4+
const net = require('net');
5+
const tmpdir = require('../common/tmpdir');
6+
7+
tmpdir.refresh();
8+
9+
let count = 0;
10+
let server1;
11+
let server2;
12+
13+
function request(options) {
14+
count++;
15+
http.get({
16+
...options,
17+
createConnection: (...args) => {
18+
return net.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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.