diff --git a/lib/configproxy.js b/lib/configproxy.js index 46652a51..7967527f 100644 --- a/lib/configproxy.js +++ b/lib/configproxy.js @@ -392,19 +392,19 @@ export class ConfigurableProxy extends EventEmitter { var proxyOptions = { target }; if (target.protocol.startsWith("unix")) { + // No need for agents for unix sockets + // No support for https for unix sockets proxyOptions.secure = false; proxyOptions.target.socketPath = decodeURIComponent(target.host); proxyOptions.target.pathname = (target.pathname ? target.pathname + "/" : "") + reqUrl; + } else if (target.protocol.startsWith("https")) { + proxyOptions.secure = true; + proxyOptions.agent = this.httpsAgent; + } else if (target.protocol.startsWith("http")) { + proxyOptions.secure = false; + proxyOptions.agent = this.httpAgent; } else { - // No need for agents for unix sockets - // No support for https for unix sockets - proxyOptions.secure = target.protocol.slice(-2) === "s:"; - - if (proxyOptions.secure) { - proxyOptions.agent = this.httpsAgent; - } else { - proxyOptions.agent = this.httpAgent; - } + throw new Error(`Unexpected protocol ${target.protocol}`); } if (proxyOptions.secure && this.options.clientSsl) { diff --git a/lib/testutil.js b/lib/testutil.js index 4216879a..088e6dbe 100644 --- a/lib/testutil.js +++ b/lib/testutil.js @@ -10,14 +10,16 @@ var servers = []; // TODO: make this an options dict export function addTarget(proxy, path, port, websocket, targetPath, sslOptions, unixSocketPath) { - var proto = sslOptions ? "https" : "http"; + var proto; var listenTarget; var target; if (unixSocketPath) { listenTarget = decodeURIComponent(unixSocketPath); + proto = "http"; target = "unix+" + proto + "://" + unixSocketPath; } else { + proto = sslOptions ? "https" : "http"; target = proto + "://" + "127.0.0.1:" + port; listenTarget = port; }