| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f281272 commit f5da494
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2959,6 +2959,21 @@ environment variables. | |||
| 2959 | 2959 | ||
| 2960 | 2960 | See `SSL_CERT_DIR` and `SSL_CERT_FILE`. | |
| 2961 | 2961 | ||
| 2962 | + ### `--use-env-proxy` | ||
| 2963 | + | ||
| 2964 | + <!-- YAML | ||
| 2965 | + added: REPLACEME | ||
| 2966 | + --> | ||
| 2967 | + | ||
| 2968 | + > Stability: 1.1 - Active Development | ||
| 2969 | + | ||
| 2970 | + When enabled, Node.js parses the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` | ||
| 2971 | + environment variables during startup, and tunnels requests over the | ||
| 2972 | + specified proxy. | ||
| 2973 | + | ||
| 2974 | + This is equivalent to setting the [`NODE_USE_ENV_PROXY=1`][] environment variable. | ||
| 2975 | + When both are set, `--use-env-proxy` takes precedence. | ||
| 2976 | + | ||
| 2962 | 2977 | ### `--use-largepages=mode` | |
| 2963 | 2978 | ||
| 2964 | 2979 | <!-- YAML | |
@@ -3458,6 +3473,7 @@ one is included in the list below. | |||
| 3458 | 3473 | * `--track-heap-objects` | |
| 3459 | 3474 | * `--unhandled-rejections` | |
| 3460 | 3475 | * `--use-bundled-ca` | |
| 3476 | + * `--use-env-proxy` | ||
| 3461 | 3477 | * `--use-largepages` | |
| 3462 | 3478 | * `--use-openssl-ca` | |
| 3463 | 3479 | * `--use-system-ca` | |
@@ -3613,8 +3629,8 @@ When enabled, Node.js parses the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` | |||
| 3613 | 3629 | environment variables during startup, and tunnels requests over the | |
| 3614 | 3630 | specified proxy. | |
| 3615 | 3631 | ||
| 3616 | - This currently only affects requests sent over `fetch()`. Support for other | ||
| 3617 | - built-in `http` and `https` methods is under way. | ||
| 3632 | + This can also be enabled using the [`--use-env-proxy`][] command-line flag. | ||
| 3633 | + When both are set, `--use-env-proxy` takes precedence. | ||
| 3618 | 3634 | ||
| 3619 | 3635 | ### `NODE_V8_COVERAGE=dir` | |
| 3620 | 3636 | ||
@@ -3943,12 +3959,14 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12 | |||
| 3943 | 3959 | [`--print`]: #-p---print-script | |
| 3944 | 3960 | [`--redirect-warnings`]: #--redirect-warningsfile | |
| 3945 | 3961 | [`--require`]: #-r---require-module | |
| 3962 | + [`--use-env-proxy`]: #--use-env-proxy | ||
| 3946 | 3963 | [`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage | |
| 3947 | 3964 | [`Buffer`]: buffer.md#class-buffer | |
| 3948 | 3965 | [`CRYPTO_secure_malloc_init`]: https://www.openssl.org/docs/man3.0/man3/CRYPTO_secure_malloc_init.html | |
| 3949 | 3966 | [`ERR_INVALID_TYPESCRIPT_SYNTAX`]: errors.md#err_invalid_typescript_syntax | |
| 3950 | 3967 | [`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`]: errors.md#err_unsupported_typescript_syntax | |
| 3951 | 3968 | [`NODE_OPTIONS`]: #node_optionsoptions | |
| 3969 | + [`NODE_USE_ENV_PROXY=1`]: #node_use_env_proxy1 | ||
| 3952 | 3970 | [`NO_COLOR`]: https://no-color.org | |
| 3953 | 3971 | [`SlowBuffer`]: buffer.md#class-slowbuffer | |
| 3954 | 3972 | [`Web Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2499,7 +2499,7 @@ Failed to proxy a request because the proxy configuration is invalid. | |||
| 2499 | 2499 | ||
| 2500 | 2500 | ### `ERR_PROXY_TUNNEL` | |
| 2501 | 2501 | ||
| 2502 | - Failed to establish proxy tunnel when `NODE_USE_ENV_PROXY` is enabled. | ||
| 2502 | + Failed to establish proxy tunnel when `NODE_USE_ENV_PROXY` or `--use-env-proxy` is enabled. | ||
| 2503 | 2503 | ||
| 2504 | 2504 | <a id="ERR_QUIC_APPLICATION_ERROR"></a> | |
| 2505 | 2505 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4273,10 +4273,9 @@ added: REPLACEME | |||
| 4273 | 4273 | ||
| 4274 | 4274 | > Stability: 1.1 - Active development | |
| 4275 | 4275 | ||
| 4276 | - When Node.js creates the global agent, it checks the `NODE_USE_ENV_PROXY` | ||
| 4277 | - environment variable. If it is set to `1`, the global agent will be constructed | ||
| 4276 | + When Node.js creates the global agent, if the `NODE_USE_ENV_PROXY` environment variable is | ||
| 4277 | + set to `1` or `--use-env-proxy` is enabled, the global agent will be constructed | ||
| 4278 | 4278 | with `proxyEnv: process.env`, enabling proxy support based on the environment variables. | |
| 4279 | - | ||
| 4280 | 4279 | Custom agents can also be created with proxy support by passing a | |
| 4281 | 4280 | `proxyEnv` option when constructing the agent. The value can be `process.env` | |
| 4282 | 4281 | if they just want to inherit the configuration from the environment variables, | |
@@ -4318,13 +4317,20 @@ Multiple entries should be separated by commas. | |||
| 4318 | 4317 | ||
| 4319 | 4318 | ### Example | |
| 4320 | 4319 | ||
| 4321 | - Starting a Node.js process with proxy support enabled for all requests sent | ||
| 4322 | - through the default global agent: | ||
| 4320 | + To start a Node.js process with proxy support enabled for all requests sent | ||
| 4321 | + through the default global agent, either use the `NODE_USE_ENV_PROXY` environment | ||
| 4322 | + variable: | ||
| 4323 | 4323 | ||
| 4324 | 4324 | ```console | |
| 4325 | 4325 | NODE_USE_ENV_PROXY=1 HTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node client.js | |
| 4326 | 4326 | ``` | |
| 4327 | 4327 | ||
| 4328 | + Or the `--use-env-proxy` flag. | ||
| 4329 | + | ||
| 4330 | + ```console | ||
| 4331 | + HTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node --use-env-proxy client.js | ||
| 4332 | + ``` | ||
| 4333 | + | ||
| 4328 | 4334 | To create a custom agent with built-in proxy support: | |
| 4329 | 4335 | ||
| 4330 | 4336 | ```cjs | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -538,6 +538,9 @@ | |||
| 538 | 538 | "use-bundled-ca": { | |
| 539 | 539 | "type": "boolean" | |
| 540 | 540 | }, | |
| 541 | + "use-env-proxy": { | ||
| 542 | + "type": "boolean" | ||
| 543 | + }, | ||
| 541 | 544 | "use-largepages": { | |
| 542 | 545 | "type": "string" | |
| 543 | 546 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -600,6 +600,9 @@ See | |||
| 600 | 600 | and | |
| 601 | 601 | .Ev SSL_CERT_FILE . | |
| 602 | 602 | . | |
| 603 | + .It Fl -use-env-proxy | ||
| 604 | + Parse proxy settings from HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables and apply the setting in global HTTP/HTTPS clients. | ||
| 605 | + . | ||
| 603 | 606 | .It Fl -use-largepages Ns = Ns Ar mode | |
| 604 | 607 | Re-map the Node.js static code to large memory pages at startup. If supported on | |
| 605 | 608 | the target system, this will cause the Node.js static code to be moved onto 2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,7 @@ const { | |||
| 54 | 54 | validateString, | |
| 55 | 55 | } = require('internal/validators'); | |
| 56 | 56 | const assert = require('internal/assert'); | |
| 57 | + const { getOptionValue } = require('internal/options'); | ||
| 57 | 58 | ||
| 58 | 59 | const kOnKeylog = Symbol('onkeylog'); | |
| 59 | 60 | const kRequestOptions = Symbol('requestOptions'); | |
@@ -622,6 +623,7 @@ module.exports = { | |||
| 622 | 623 | Agent, | |
| 623 | 624 | globalAgent: new Agent({ | |
| 624 | 625 | keepAlive: true, scheduling: 'lifo', timeout: 5000, | |
| 625 | - proxyEnv: process.env.NODE_USE_ENV_PROXY ? filterEnvForProxies(process.env) : undefined, | ||
| 626 | + // This normalized from both --use-env-proxy and NODE_USE_ENV_PROXY settings. | ||
| 627 | + proxyEnv: getOptionValue('--use-env-proxy') ? filterEnvForProxies(process.env) : undefined, | ||
| 626 | 628 | }), | |
| 627 | 629 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,7 @@ const { URL, urlToHttpOptions, isURL } = require('internal/url'); | |||
| 70 | 70 | const { validateObject } = require('internal/validators'); | |
| 71 | 71 | const { isIP, isIPv6 } = require('internal/net'); | |
| 72 | 72 | const assert = require('internal/assert'); | |
| 73 | + const { getOptionValue } = require('internal/options'); | ||
| 73 | 74 | ||
| 74 | 75 | function Server(opts, requestListener) { | |
| 75 | 76 | if (!(this instanceof Server)) return new Server(opts, requestListener); | |
@@ -599,7 +600,8 @@ Agent.prototype._evictSession = function _evictSession(key) { | |||
| 599 | 600 | ||
| 600 | 601 | const globalAgent = new Agent({ | |
| 601 | 602 | keepAlive: true, scheduling: 'lifo', timeout: 5000, | |
| 602 | - proxyEnv: process.env.NODE_USE_ENV_PROXY ? filterEnvForProxies(process.env) : undefined, | ||
| 603 | + // This normalized from both --use-env-proxy and NODE_USE_ENV_PROXY settings. | ||
| 604 | + proxyEnv: getOptionValue('--use-env-proxy') ? filterEnvForProxies(process.env) : undefined, | ||
| 603 | 605 | }); | |
| 604 | 606 | ||
| 605 | 607 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,19 +166,24 @@ function prepareExecution(options) { | |||
| 166 | 166 | } | |
| 167 | 167 | ||
| 168 | 168 | function setupHttpProxy() { | |
| 169 | - if (process.env.NODE_USE_ENV_PROXY && | ||
| 170 | - (process.env.HTTP_PROXY || process.env.HTTPS_PROXY || | ||
| 171 | - process.env.http_proxy || process.env.https_proxy)) { | ||
| 172 | - const { setGlobalDispatcher, EnvHttpProxyAgent } = require('internal/deps/undici/undici'); | ||
| 173 | - const envHttpProxyAgent = new EnvHttpProxyAgent(); | ||
| 174 | - setGlobalDispatcher(envHttpProxyAgent); | ||
| 175 | - // For fetch, we need to set the global dispatcher from here. | ||
| 176 | - // For http/https agents, we'll configure the global agent when they are | ||
| 177 | - // actually created, in lib/_http_agent.js and lib/https.js. | ||
| 178 | - // TODO(joyeecheung): This is currently guarded with NODE_USE_ENV_PROXY. Investigate whether | ||
| 179 | - // it's possible to enable it by default without stepping on other existing libraries that | ||
| 180 | - // sets the global dispatcher or monkey patches the global agent. | ||
| 169 | + // This normalized from both --use-env-proxy and NODE_USE_ENV_PROXY settings. | ||
| 170 | + if (!getOptionValue('--use-env-proxy')) { | ||
| 171 | + return; | ||
| 172 | + } | ||
| 173 | + if (!process.env.HTTP_PROXY && !process.env.HTTPS_PROXY && | ||
| 174 | + !process.env.http_proxy && !process.env.https_proxy) { | ||
| 175 | + return; | ||
| 181 | 176 | } | |
| 177 | + | ||
| 178 | + const { setGlobalDispatcher, EnvHttpProxyAgent } = require('internal/deps/undici/undici'); | ||
| 179 | + const envHttpProxyAgent = new EnvHttpProxyAgent(); | ||
| 180 | + setGlobalDispatcher(envHttpProxyAgent); | ||
| 181 | + // For fetch, we need to set the global dispatcher from here. | ||
| 182 | + // For http/https agents, we'll configure the global agent when they are | ||
| 183 | + // actually created, in lib/_http_agent.js and lib/https.js. | ||
| 184 | + // TODO(joyeecheung): This is currently guarded with NODE_USE_ENV_PROXY and --use-env-proxy. | ||
| 185 | + // Investigate whether it's possible to enable it by default without stepping on other | ||
| 186 | + // existing libraries that sets the global dispatcher or monkey patches the global agent. | ||
| 182 | 187 | } | |
| 183 | 188 | ||
| 184 | 189 | function setupUserModules(forceDefaultLoader = false) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -660,6 +660,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 660 | 660 | "emit pending deprecation warnings", | |
| 661 | 661 | &EnvironmentOptions::pending_deprecation, | |
| 662 | 662 | kAllowedInEnvvar); | |
| 663 | + AddOption("--use-env-proxy", | ||
| 664 | + "parse proxy settings from HTTP_PROXY/HTTPS_PROXY/NO_PROXY" | ||
| 665 | + "environment variables and apply the setting in global HTTP/HTTPS " | ||
| 666 | + "clients", | ||
| 667 | + &EnvironmentOptions::use_env_proxy, | ||
| 668 | + kAllowedInEnvvar); | ||
| 663 | 669 | AddOption("--preserve-symlinks", | |
| 664 | 670 | "preserve symbolic links when resolving", | |
| 665 | 671 | &EnvironmentOptions::preserve_symlinks, | |
@@ -1875,6 +1881,8 @@ void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options, | |||
| 1875 | 1881 | env_options->preserve_symlinks_main = | |
| 1876 | 1882 | opt_getter("NODE_PRESERVE_SYMLINKS_MAIN") == "1"; | |
| 1877 | 1883 | ||
| 1884 | + env_options->use_env_proxy = opt_getter("NODE_USE_ENV_PROXY") == "1"; | ||
| 1885 | + | ||
| 1878 | 1886 | if (env_options->redirect_warnings.empty()) | |
| 1879 | 1887 | env_options->redirect_warnings = opt_getter("NODE_REDIRECT_WARNINGS"); | |
| 1880 | 1888 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -241,6 +241,7 @@ class EnvironmentOptions : public Options { | |||
| 241 | 241 | bool force_repl = false; | |
| 242 | 242 | ||
| 243 | 243 | bool insecure_http_parser = false; | |
| 244 | + bool use_env_proxy = false; | ||
| 244 | 245 | ||
| 245 | 246 | bool tls_min_v1_0 = false; | |
| 246 | 247 | bool tls_min_v1_1 = false; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments