Skip to content
Closed
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
2 changes: 1 addition & 1 deletion app/steps/decorateUserResHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

function decorateUserResHeaders(container) {
var resolverFn = container.options.userResHeaderDecorator;
var headers = container.user.res._headers;
var headers = container.user.res.getHeaders ? container.user.res.getHeaders() : container.user.res._headers;

if (!resolverFn) {
return Promise.resolve(container);
Expand Down
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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for using a promise here for consistency

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
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/userResDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('userResDecorator', function () {

proxyApp.use(proxy(redirectingServerOrigin, {
userResDecorator: function (rsp, data, req, res) {
var proxyReturnedLocation = res._headers.location;
var proxyReturnedLocation = res.getHeaders ? res.getHeaders().location : res._headers.location;
res.location(proxyReturnedLocation.replace(redirectingServerPort, preferredPort));
return data;
}
Expand Down