-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
I believe this will be a notable change. |
The
notable-change
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
There was a problem hiding this comment.
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.
Depends on #57236 @mcollina why is this semver-major? I think if we make it behind another environment variable first (NODE_USE_HTTP_PROXY in this PR, can change to a different name if a better one comes up), this is still semver-minor, and only another PR that makes it enabled by default and have to be disabled explicitly would be semver-major? |
The HTTP_PROXY env is used also by other programs, so it's relatively possible that it's set in an environment, making it a behavior change. |
Would the intention be to limit this to just undici/fetch? That is, would this also work for |
Given how the current http.Agent work, I'm not entirely sure it's possible to enable it by default without breaking some part of the ecosystem unexpectedly(see the monkeypatching that nock does, as well as observability providers). |
I think a probable path forward would be:
3 and 4 can be done independently. In the worst case, we stop at 2, but at least it still allows users being trapped by firewalls and not always having control over the code making requests to opt into a solution that solves their headaches by setting the environment variable, which might be good enough for many already. I think 3 might not be that risky, 4 will need some investigation, but we can use 2 to let users try it out and explore any possible interop problems with existing libraries. So I expect 2 would need a bit more time to fully develop but since it's opt-in as an experimental feature it seems pretty reasonable. |
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 variablesHTTP_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