Skip to content

Commit

Permalink
fix: scope variables used by Agent constructor
Browse files Browse the repository at this point in the history
Some packages that consume http(s).Agent (e.g. tunnel-agent) attempt to construct http.Agent using .constructor and without providing the required constructor parameters.
  • Loading branch information
gajus committed Jun 21, 2019
1 parent 50d4ee6 commit f17386d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"scripts": {
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
"dev": "NODE_ENV=development babel ./src --out-dir ./dist --copy-files --source-maps --watch",
"lint": "eslint ./src ./test && flow",
"test": "NODE_ENV=test nyc ava --verbose --serial"
},
Expand Down
40 changes: 26 additions & 14 deletions src/factories/createGlobalProxyAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,37 @@ export default (configurationInput: ProxyAgentConfigurationInputType = defaultCo
return proxyController.HTTP_PROXY;
};

const httpAgent = new HttpProxyAgent(
isProxyConfigured(getHttpProxy),
mustUrlUseProxy(getHttpProxy),
getUrlProxy(getHttpProxy),
http.globalAgent,
eventEmitter
);
const BoundHttpProxyAgent = class extends HttpProxyAgent {
constructor () {
super(
isProxyConfigured(getHttpProxy),
mustUrlUseProxy(getHttpProxy),
getUrlProxy(getHttpProxy),
http.globalAgent,
eventEmitter
);
}
};

const httpAgent = new BoundHttpProxyAgent();

const getHttpsProxy = () => {
return proxyController.HTTPS_PROXY || proxyController.HTTP_PROXY;
};

const httpsAgent = new HttpsProxyAgent(
isProxyConfigured(getHttpsProxy),
mustUrlUseProxy(getHttpsProxy),
getUrlProxy(getHttpsProxy),
https.globalAgent,
eventEmitter
);
const BoundHttpsProxyAgent = class extends HttpsProxyAgent {
constructor () {
super(
isProxyConfigured(getHttpsProxy),
mustUrlUseProxy(getHttpsProxy),
getUrlProxy(getHttpsProxy),
https.globalAgent,
eventEmitter
);
}
};

const httpsAgent = new BoundHttpsProxyAgent();

// Overriding globalAgent was added in v11.7.
// @see https://nodejs.org/uk/blog/release/v11.7.0/
Expand Down

0 comments on commit f17386d

Please sign in to comment.