Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for async host functions. #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions app/steps/resolveProxyHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ function resolveProxyHost(container) {
parsedHost = requestOptions.parseHost(container);
}

container.proxy.reqBuilder.host = parsedHost.host;
container.proxy.reqBuilder.port = container.options.port || parsedHost.port;
container.proxy.requestModule = parsedHost.module;
return Promise.resolve(container);
return Promise.resolve(parsedHost).then((parsedHost) => {
container.proxy.reqBuilder.host = parsedHost.host;
container.proxy.reqBuilder.port = container.options.port || parsedHost.port;
container.proxy.requestModule = parsedHost.module;
return Promise.resolve(container);
});
}

module.exports = resolveProxyHost;
28 changes: 15 additions & 13 deletions lib/requestOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ function parseHost(Container) {
return new Error('Empty host parameter');
}

if (!/http(s)?:\/\//.test(host)) {
host = 'http://' + host;
}
return Promise.resolve(host).then((host) => {
if (!/http(s)?:\/\//.test(host)) {
host = 'http://' + host;
}

var parsed = url.parse(host);
var parsed = url.parse(host);

if (!parsed.hostname) {
return new Error('Unable to parse hostname, possibly missing protocol://?');
}
if (!parsed.hostname) {
return new Error('Unable to parse hostname, possibly missing protocol://?');
}

var ishttps = options.https || parsed.protocol === 'https:';
var ishttps = options.https || parsed.protocol === 'https:';

return {
host: parsed.hostname,
port: parsed.port || (ishttps ? 443 : 80),
module: ishttps ? https : http,
};
return {
host: parsed.hostname,
port: parsed.port || (ishttps ? 443 : 80),
module: ishttps ? https : http,
};
});
}

function reqHeaders(req, options) {
Expand Down