From 5e1a4fa3e4fdbd936e939ba9672e1fc9bcb8b4e9 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 26 Jul 2025 19:35:47 +0300 Subject: [PATCH 1/2] buffer: cache Environment::GetCurrent to avoid repeated calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/59043 Reviewed-By: James M Snell Reviewed-By: theanarkh Reviewed-By: Dario Piotrowicz Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli --- src/node_buffer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index c356a22bec23bf..2fff0488cd81cd 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1061,8 +1061,9 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { enum encoding enc = static_cast(args[3].As()->Value()); - THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); - THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[1]); + Environment* env = Environment::GetCurrent(args); + THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); + THROW_AND_RETURN_UNLESS_BUFFER(env, args[1]); ArrayBufferViewContents haystack_contents(args[0]); ArrayBufferViewContents needle_contents(args[1]); int64_t offset_i64 = args[2].As()->Value(); From 0259df9faf9ff782c417552f4ce3ed96dc9f3254 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 26 Jul 2025 22:43:10 +0200 Subject: [PATCH 2/2] 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 6778d3db33bf53..ca6e0e684ed6fd 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`