Skip to content

Commit

Permalink
network: override addRequest in HttpAgent, not createSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 4, 2019
1 parent 5f678a2 commit 768381b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/network/lib/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class CombinedAgent {
}

// called by Node.js whenever a new request is made internally
// TODO: need to support legacy invocation? https://github.com/nodejs/node/blob/cb68c04ce1bc4534b2d92bc7319c6ff6dda0180d/lib/_http_agent.js#L148-L155
addRequest(req: http.ClientRequest, options: http.RequestOptions) {
const isHttps = isRequestHttps(options)

Expand Down Expand Up @@ -182,22 +183,22 @@ class HttpAgent extends http.Agent {
this.httpsAgent = new https.Agent({ keepAlive: true })
}

createSocket (req: http.ClientRequest, options: http.RequestOptions, cb: http.SocketCallback) {
addRequest (req: http.ClientRequest, options: http.RequestOptions) {
if (process.env.HTTP_PROXY) {
const proxy = getProxyForUrl(options.href)

if (proxy) {
options.proxy = proxy

return this._createProxiedSocket(req, <RequestOptionsWithProxy>options, cb)
this._addProxiedRequest(req, <RequestOptionsWithProxy>options)
}
}

super.createSocket(req, options, cb)
super.addRequest(req, options)
}

_createProxiedSocket (req: http.ClientRequest, options: RequestOptionsWithProxy, cb: http.SocketCallback) {
debug(`Creating proxied socket for ${options.href} through ${options.proxy}`)
_addProxiedRequest (req: http.ClientRequest, options: RequestOptionsWithProxy) {
debug(`Creating proxied request for ${options.href} through ${options.proxy}`)

const proxy = url.parse(options.proxy)

Expand Down Expand Up @@ -228,7 +229,7 @@ class HttpAgent extends http.Agent {
return this.httpsAgent.addRequest(req, options)
}

super.createSocket(req, options, cb)
super.addRequest(req, options)
}
}

Expand Down

0 comments on commit 768381b

Please sign in to comment.