Skip to content

fix: auto-detect HTTP proxy tunneling#5116

Open
mcollina wants to merge 1 commit intomainfrom
fix/proxy-tunnel-autodetection
Open

fix: auto-detect HTTP proxy tunneling#5116
mcollina wants to merge 1 commit intomainfrom
fix/proxy-tunnel-autodetection

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Apr 25, 2026

This relates to...

Fixes #5093

Rationale

EnvHttpProxyAgent currently inherits ProxyAgent's tunneling behavior. For plain HTTP targets reached through an HTTP proxy, defaulting to CONNECT can break proxies that do not implement tunneling and can lead to the looping behavior reported in #5093.

Changes

  • auto-detect whether tunneling is required in ProxyAgent
  • keep tunneling enabled whenever either the proxy or the target endpoint is secure
  • keep plain HTTP over HTTP proxy requests non-tunneled by default, while preserving proxyTunnel: true as an explicit override
  • add regression coverage for EnvHttpProxyAgent using http_proxy
  • update the ProxyAgent docs and type comment to describe the new behavior

Features

N/A

Bug Fixes

Breaking Changes and Deprecations

None

Status

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina force-pushed the fix/proxy-tunnel-autodetection branch from be4138f to d6abdf6 Compare April 25, 2026 15:55
@trivikr
Copy link
Copy Markdown
Member

trivikr commented Apr 25, 2026

Should proxyTunnel be set to true on line 76 in test/env-http-proxy-agent-nodejs-bundle.js?

-    setGlobalDispatcher(new EnvHttpProxyAgent())
+    setGlobalDispatcher(new EnvHttpProxyAgent({ proxyTunnel: true }))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use of HTTP_PROXY & NODE_USE_ENV_PROXY fails with an infinite loop

3 participants