From 9a8e0d8433ce298247a7087708ac2895b4a506bd Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Sat, 29 Jun 2019 09:24:44 +0100 Subject: [PATCH] fix: handle path as an absolute URL --- src/classes/Agent.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/classes/Agent.js b/src/classes/Agent.js index 04c661ca..875fdcb2 100644 --- a/src/classes/Agent.js +++ b/src/classes/Agent.js @@ -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({