Skip to content

Commit

Permalink
parse hostname from options instead of headers (#430)
Browse files Browse the repository at this point in the history
* parse hostname from options instead of headers

* get host from request instead

* updated harness
  • Loading branch information
willarmiros authored May 19, 2021
1 parent ff228ee commit c28ae79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function RemoteRequestData(req, res, downstreamXRayEnabled) {

RemoteRequestData.prototype.init = function init(req, res, downstreamXRayEnabled) {
this.request = {
url: (req.agent && req.agent.protocol) ? (req.agent.protocol + '//' + req.getHeader('host') + stripQueryStringFromPath(req.path)) : '',
url: (req.agent && req.agent.protocol) ? (req.agent.protocol + '//' + (req.host || req.getHeader('host')) + stripQueryStringFromPath(req.path)) : '',
method: req.method || '',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ describe('RemoteRequestData', function() {
agent: {
protocol: 'https:'
},
getHeader: function() {
return 'host.com';
getHeader: (key) => {
if (key === 'host') {
return 'host.com';
}
return undefined;
},
path: '/path/to/resource'
};
Expand Down Expand Up @@ -50,5 +53,14 @@ describe('RemoteRequestData', function() {
''
);
});
it('should use the host from the request object over headers', () => {
const requestWithHost = Object.assign(request, { host: 'different-site.com' });

assert.propertyVal(
new RemoteRequestData(requestWithHost, response, true).request,
'url',
'https://different-site.com/path/to/resource'
);
});
});
});

0 comments on commit c28ae79

Please sign in to comment.