Skip to content

fix: auto-detect HTTP proxy tunneling#5116

Open
mcollina wants to merge 2 commits into
mainfrom
fix/proxy-tunnel-autodetection
Open

fix: auto-detect HTTP proxy tunneling#5116
mcollina wants to merge 2 commits into
mainfrom
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 }))

@mvolz
Copy link
Copy Markdown

mvolz commented May 11, 2026

Thanks for submitting this!

Do we have a sense of when this might make it into to a published branch? The reason I ask is that we're trying to replace request with fetch, but our outbound proxy rejects CONNECT requests for https so this is a blocker... trying to decide whether to revert all of it and go back to request we're in a deployable state, or if it's reasonable to wait for this change.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
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

4 participants