From 4b0007d676f81f4df160b5e6b1ad19e54d9b0f2e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 24 Apr 2026 14:25:01 +0000 Subject: [PATCH] lib: add NODE_PROXY_TUNNEL env var to disable CONNECT tunneling When NODE_USE_ENV_PROXY or --use-env-proxy is enabled and the proxy does not support the HTTP CONNECT method, undici loops forever retrying CONNECT requests. Add NODE_PROXY_TUNNEL env var to control whether proxy connections use CONNECT tunneling. When set to false/0, EnvHttpProxyAgent passes proxyTunnel: false to ProxyAgent, which uses Http1ProxyWrapper for direct HTTP forwarding instead of CONNECT tunneling. Refs: https://github.com/nodejs/undici/issues/5093 --- doc/api/cli.md | 23 ++++++- doc/api/http.md | 7 ++ doc/node.1 | 10 +++ lib/internal/process/pre_execution.js | 7 +- test/client-proxy/test-node-proxy-tunnel.mjs | 72 ++++++++++++++++++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 test/client-proxy/test-node-proxy-tunnel.mjs diff --git a/doc/api/cli.md b/doc/api/cli.md index e979ec95c4259d..8fe177a2cf0437 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -3903,6 +3903,25 @@ added: v7.1.0 When set to `1`, instructs the module loader to preserve symbolic links when resolving and caching modules. +### `NODE_PROXY_TUNNEL` + + + +> Stability: 1.1 - Active Development + +When `NODE_USE_ENV_PROXY=1` or `--use-env-proxy` is enabled, controls whether +proxy connections use the HTTP CONNECT tunneling method. + +When set to `true` or `1` (the default), undici uses CONNECT tunneling to establish +a proxy connection. When set to `false` or `0`, undici uses direct HTTP forwarding +instead, which may be required for proxies that do not support the CONNECT method. + +Valid values: `true`, `1`, `false`, `0`. + +See also [`NODE_USE_ENV_PROXY=1`][]. + ### `NODE_REDIRECT_WARNINGS=file`