Skip to content

Commit

Permalink
fix: handle path as an absolute URL
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 29, 2019
1 parent 92bf710 commit 9a8e0d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/classes/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ class Agent {
}

addRequest (request: *, configuration: *) {
const requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
let requestUrl;

// It is possible that addRequest was constructed for a proxied request already, e.g.
// "request" package does this when it detects that a proxy should be used
// https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
// https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
requestUrl = request.path;
} else {
requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
}

if (!this.isProxyConfigured()) {
log.trace({
Expand Down

0 comments on commit 9a8e0d8

Please sign in to comment.