Skip to content

Commit 1a6094a

Browse files
authored
Merge pull request #597 from agoose77/connect_to_unix_socket
Follow up #592
2 parents eabdd7d + c5c081e commit 1a6094a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/configproxy.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,19 @@ export class ConfigurableProxy extends EventEmitter {
392392
var proxyOptions = { target };
393393

394394
if (target.protocol.startsWith("unix")) {
395+
// No need for agents for unix sockets
396+
// No support for https for unix sockets
395397
proxyOptions.secure = false;
396398
proxyOptions.target.socketPath = decodeURIComponent(target.host);
397399
proxyOptions.target.pathname = (target.pathname ? target.pathname + "/" : "") + reqUrl;
400+
} else if (target.protocol.startsWith("https")) {
401+
proxyOptions.secure = true;
402+
proxyOptions.agent = this.httpsAgent;
403+
} else if (target.protocol.startsWith("http")) {
404+
proxyOptions.secure = false;
405+
proxyOptions.agent = this.httpAgent;
398406
} else {
399-
// No need for agents for unix sockets
400-
// No support for https for unix sockets
401-
proxyOptions.secure = target.protocol.slice(-2) === "s:";
402-
403-
if (proxyOptions.secure) {
404-
proxyOptions.agent = this.httpsAgent;
405-
} else {
406-
proxyOptions.agent = this.httpAgent;
407-
}
407+
throw new Error(`Unexpected protocol ${target.protocol}`);
408408
}
409409

410410
if (proxyOptions.secure && this.options.clientSsl) {

lib/testutil.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ var servers = [];
1010

1111
// TODO: make this an options dict
1212
export function addTarget(proxy, path, port, websocket, targetPath, sslOptions, unixSocketPath) {
13-
var proto = sslOptions ? "https" : "http";
13+
var proto;
1414
var listenTarget;
1515
var target;
1616

1717
if (unixSocketPath) {
1818
listenTarget = decodeURIComponent(unixSocketPath);
19+
proto = "http";
1920
target = "unix+" + proto + "://" + unixSocketPath;
2021
} else {
22+
proto = sslOptions ? "https" : "http";
2123
target = proto + "://" + "127.0.0.1:" + port;
2224
listenTarget = port;
2325
}

0 commit comments

Comments
 (0)