Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/configproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,19 @@ export class ConfigurableProxy extends EventEmitter {
var proxyOptions = { target };

if (target.protocol.startsWith("unix")) {
// No need for agents for unix sockets
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment belongs here.

// 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;
Comment on lines +400 to +405
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more robust to close the set of protocols.

} 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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/testutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Comment on lines +19 to +22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force HTTP for unix

target = proto + "://" + "127.0.0.1:" + port;
listenTarget = port;
}
Expand Down