Skip to content

Commit

Permalink
support legacy addRequest invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 11, 2019
1 parent ae439aa commit 890e38a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/network/lib/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,18 @@ 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) {
addRequest(req: http.ClientRequest, options: http.RequestOptions, port?: number, localAddress?: string) {
// Legacy API: addRequest(req, host, port, localAddress)
// https://github.com/nodejs/node/blob/cb68c04ce1bc4534b2d92bc7319c6ff6dda0180d/lib/_http_agent.js#L148-L155
if (typeof options === 'string') {
// @ts-ignore
options = {
host: options,
port: port!,
localAddress
}
}

const isHttps = isRequestHttps(options)

if (!options.href) {
Expand Down Expand Up @@ -190,7 +200,7 @@ class HttpAgent extends http.Agent {
if (proxy) {
options.proxy = proxy

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

Expand Down

0 comments on commit 890e38a

Please sign in to comment.