Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: support HTTP[S]_PROXY environment variables #57165

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 21, 2025

This is currently a POC. Just trying to open a PR first to see what folks think about this approach - that is, to support HTTP_PROXY etc. environment variables out of the box. The exposure of the lower-level dispatcher and EnvHttpProxyAgent would be a different feature, but I think for many users, having the environment variables supported out of the box is already enough or more important to solve their headaches, while the lower-level utilities are less essential - many other language runtimes/command line tools only support these environment variables out of the box, without necessarily providing more utilities for further customization, and that seems enough for most people who are behind a proxy already.

The idea is that we can first make this handling opt-in via another environment variable (NODE_USE_ENV_PROXY here, or we can use others if there are better names). And in the future we can enable this flag by default, as this is still opt-in under well-known environment variables HTTP_PROXY. I think some investigation is needed to make sure that enabling it by default would not step on the toes of other libraries/tools already recognizing these environment variables and do their own thing.

This requires a patch in undici to make the EnvHttpProxyAgent usable from the Node.js bundle, which I included locally in this PR and a locally built bundle for demonstration purpose. I opened a separate PR to undici to see what's the best way to patch it nodejs/undici#4064

I've only tested it with fetch so far, and left a TODO for handling of http global agents.

Refs: nodejs/undici#1650

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 21, 2025
@joyeecheung joyeecheung changed the title http: support http proxy for fetch under NODE_USE_ENV_PROXY http: support HTTP_PROXY environment variables Feb 21, 2025
@joyeecheung
Copy link
Member Author

cc @mcollina @ronag (maybe there are others that I am forgetting, but you held the floor most of the time in the session in the London summit about this :))

@joyeecheung joyeecheung changed the title http: support HTTP_PROXY environment variables http: support HTTP[S]_PROXY environment variables Feb 21, 2025
@legendecas
Copy link
Member

I believe this will be a notable change.

@legendecas legendecas added the notable-change PRs with changes that should be highlighted in changelogs. label Feb 21, 2025
Copy link
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @legendecas.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@@ -26,6 +26,10 @@ module.exports.createFastMessageEvent = createFastMessageEvent

module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource

const api = require('./lib/api')
const Dispatcher = require('./lib/dispatcher/dispatcher')
Object.assign(Dispatcher.prototype, api)
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Member Author

@joyeecheung joyeecheung Feb 21, 2025

Choose a reason for hiding this comment

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

I opened a separate PR in undici nodejs/undici#4064 , let's discuss it there.

@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants