From 0259df9faf9ff782c417552f4ce3ed96dc9f3254 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 26 Jul 2025 22:43:10 +0200 Subject: [PATCH] cli: add --use-env-proxy This does the same as NODE_USE_ENV_PROXY. When both are set, like other options that can be configured from both sides, the CLI flag takes precedence. PR-URL: https://github.com/nodejs/node/pull/59151 Fixes: https://github.com/nodejs/node/issues/59100 Reviewed-By: Ilyas Shabi Reviewed-By: Matteo Collina --- doc/api/cli.md | 22 +++- doc/api/errors.md | 2 +- doc/api/http.md | 16 ++- doc/node-config-schema.json | 3 + doc/node.1 | 3 + lib/_http_agent.js | 4 +- lib/https.js | 4 +- lib/internal/process/pre_execution.js | 29 +++-- src/node_options.cc | 8 ++ src/node_options.h | 1 + test/client-proxy/test-http-proxy-request.mjs | 2 - .../client-proxy/test-https-proxy-request.mjs | 2 - .../test-use-env-proxy-cli-http.mjs | 75 +++++++++++ .../test-use-env-proxy-cli-https.mjs | 81 ++++++++++++ .../test-use-env-proxy-precedence.mjs | 117 ++++++++++++++++++ test/common/proxy-server.js | 8 +- 16 files changed, 347 insertions(+), 30 deletions(-) create mode 100644 test/client-proxy/test-use-env-proxy-cli-http.mjs create mode 100644 test/client-proxy/test-use-env-proxy-cli-https.mjs create mode 100644 test/client-proxy/test-use-env-proxy-precedence.mjs diff --git a/doc/api/cli.md b/doc/api/cli.md index 6778d3db33b..ca6e0e684ed 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2999,6 +2999,21 @@ environment variables. See `SSL_CERT_DIR` and `SSL_CERT_FILE`. +### `--use-env-proxy` + + + +> Stability: 1.1 - Active Development + +When enabled, Node.js parses the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` +environment variables during startup, and tunnels requests over the +specified proxy. + +This is equivalent to setting the [`NODE_USE_ENV_PROXY=1`][] environment variable. +When both are set, `--use-env-proxy` takes precedence. + ### `--use-largepages=mode`