diff --git a/src/classes/Agent.js b/src/classes/Agent.js index 87a727d0..e7f55153 100644 --- a/src/classes/Agent.js +++ b/src/classes/Agent.js @@ -14,6 +14,8 @@ const log = Logger.child({ }); class Agent { + defaultPort: number; + protocol: ProtocolType; fallbackAgent: AgentType; @@ -22,8 +24,7 @@ class Agent { getUrlProxy: GetUrlProxyMethodType; - constructor (protocol: ProtocolType, mustUrlUseProxy: MustUrlUseProxyMethodType, getUrlProxy: GetUrlProxyMethodType, fallbackAgent: AgentType) { - this.protocol = protocol; + constructor (mustUrlUseProxy: MustUrlUseProxyMethodType, getUrlProxy: GetUrlProxyMethodType, fallbackAgent: AgentType) { this.fallbackAgent = fallbackAgent; this.mustUrlUseProxy = mustUrlUseProxy; this.getUrlProxy = getUrlProxy; @@ -38,11 +39,13 @@ class Agent { }); if (this.mustUrlUseProxy(requestUrl)) { - request.path = requestUrl; + if (this.protocol === 'http:') { + request.path = requestUrl; + } const proxy = this.getUrlProxy(requestUrl); - log.trace('proxying request to %s use %s proxy', requestUrl, 'http://' + proxy.hostname + ':' + proxy.port); + log.trace('proxying request to %s using %s proxy', requestUrl, 'http://' + proxy.hostname + ':' + proxy.port); request.shouldKeepAlive = false; diff --git a/src/classes/HttpProxyAgent.js b/src/classes/HttpProxyAgent.js index 3b052d95..7a9fea40 100644 --- a/src/classes/HttpProxyAgent.js +++ b/src/classes/HttpProxyAgent.js @@ -8,6 +8,15 @@ import type { import Agent from './Agent'; class HttpProxyAgent extends Agent { + // @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290 + // eslint-disable-next-line unicorn/prevent-abbreviations + constructor (...args: *) { + super(...args); + + this.protocol = 'http:'; + this.defaultPort = 80; + } + createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) { const socket = net.connect( configuration.proxy.port, diff --git a/src/classes/HttpsProxyAgent.js b/src/classes/HttpsProxyAgent.js index 0a38ae7f..7f172d24 100644 --- a/src/classes/HttpsProxyAgent.js +++ b/src/classes/HttpsProxyAgent.js @@ -9,6 +9,14 @@ import type { import Agent from './Agent'; class HttpsProxyAgent extends Agent { + // eslint-disable-next-line unicorn/prevent-abbreviations + constructor (...args: *) { + super(...args); + + this.protocol = 'https:'; + this.defaultPort = 443; + } + createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) { const socket = net.connect( configuration.proxy.port, diff --git a/src/routines/bootstrap.js b/src/routines/bootstrap.js index f9913bc0..060664ca 100644 --- a/src/routines/bootstrap.js +++ b/src/routines/bootstrap.js @@ -63,7 +63,6 @@ export default () => { // @see https://github.com/facebook/flow/issues/7670 // $FlowFixMe http.globalAgent = new HttpProxyAgent( - 'http:', mustUrlUseProxy, getUrlProxy, http.globalAgent @@ -71,9 +70,8 @@ export default () => { // $FlowFixMe https.globalAgent = new HttpsProxyAgent( - 'https:', mustUrlUseProxy, getUrlProxy, - http.globalAgent + https.globalAgent ); };