Skip to content

Commit 5166481

Browse files
committed
http: use env proxy when agent has no proxyEnv option
When a user creates a custom agent without specifying proxyEnv but Node.js is configured to use a proxy from the environment (via --use-env-proxy or NODE_USE_ENV_PROXY), fall back to process.env. A developer can still explicitly disable proxying for an agent even when Node.js is configured to use a proxy at runtime, by passing a falsy proxyEnv explicitly. For example: const agent = new https.Agent({ proxyEnv: null }); Signed-off-by: swigger <swigger@gmail.com>
1 parent 7a11a9b commit 5166481

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/_http_agent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
NumberIsFinite,
2626
NumberParseInt,
2727
ObjectKeys,
28+
ObjectPrototypeHasOwnProperty,
2829
ObjectSetPrototypeOf,
2930
ObjectValues,
3031
Symbol,
@@ -184,7 +185,9 @@ function Agent(options) {
184185
this.options.agentKeepAliveTimeoutBuffer :
185186
1000;
186187

187-
const proxyEnv = this.options.proxyEnv;
188+
const proxyEnv = ObjectPrototypeHasOwnProperty(this.options, 'proxyEnv') ?
189+
this.options.proxyEnv :
190+
(getOptionValue('--use-env-proxy') ? process.env : undefined);
188191
if (typeof proxyEnv === 'object' && proxyEnv !== null) {
189192
this[kProxyConfig] = parseProxyConfigFromEnv(proxyEnv, this.protocol, this.keepAlive);
190193
debug(`new ${this.protocol} agent with proxy config`, this[kProxyConfig]);

0 commit comments

Comments
 (0)