Skip to content

http: use env proxy when agent has no proxyEnv option - #64528

Open
swigger wants to merge 1 commit into
nodejs:mainfrom
swigger:http-agent-use-env-proxy
Open

http: use env proxy when agent has no proxyEnv option#64528
swigger wants to merge 1 commit into
nodejs:mainfrom
swigger:http-agent-use-env-proxy

Conversation

@swigger

@swigger swigger commented Jul 16, 2026

Copy link
Copy Markdown

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 });

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Jul 16, 2026
@mcollina
mcollina requested a review from joyeecheung July 16, 2026 13:40

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening a PR! Can you please add a unit test?

@swigger
swigger force-pushed the http-agent-use-env-proxy branch from 5166481 to 19d1924 Compare July 17, 2026 07:53
@swigger

swigger commented Jul 17, 2026

Copy link
Copy Markdown
Author

Thanks for opening a PR! Can you please add a unit test?

now I refreshed the PR and a unit test included.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina

Copy link
Copy Markdown
Member

@joyeecheung I think this is a bugfix, but an argument could be made this is semver-major.

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (7a11a9b) to head (1a701f6).
⚠️ Report is 86 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64528      +/-   ##
==========================================
- Coverage   90.24%   90.12%   -0.12%     
==========================================
  Files         739      741       +2     
  Lines      241669   242079     +410     
  Branches    45543    45555      +12     
==========================================
+ Hits       218087   218177      +90     
- Misses      15150    15431     +281     
- Partials     8432     8471      +39     
Files with missing lines Coverage Δ
lib/_http_agent.js 96.13% <100.00%> (+0.01%) ⬆️

... and 78 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@swigger
swigger force-pushed the http-agent-use-env-proxy branch from 19d1924 to fc4352d Compare July 20, 2026 06:59
@joyeecheung

Copy link
Copy Markdown
Member

I think this is a bugfix, but an argument could be made this is semver-major.

--use-env-proxy / NODE_USE_ENV_PROXY are both still experimental, so I think it's fine to leave it patch

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the documentation to clarify the behavior?

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>
@swigger
swigger force-pushed the http-agent-use-env-proxy branch from fc4352d to 1a701f6 Compare July 21, 2026 02:12
@swigger

swigger commented Jul 22, 2026

Copy link
Copy Markdown
Author

Can you update the documentation to clarify the behavior?

updated

@Ethan-Arrowood Ethan-Arrowood added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Ethan-Arrowood Ethan-Arrowood added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants