Skip to content

Fix: honor HTTPS_PROXY/HTTP_PROXY in proxy-only environments#89

Merged
zdavis-rollbar merged 3 commits intomainfrom
zd/node-https-proxy
Apr 17, 2026
Merged

Fix: honor HTTPS_PROXY/HTTP_PROXY in proxy-only environments#89
zdavis-rollbar merged 3 commits intomainfrom
zd/node-https-proxy

Conversation

@zdavis-rollbar
Copy link
Copy Markdown
Contributor

@zdavis-rollbar zdavis-rollbar commented Apr 16, 2026

Summary

  • Fixes EAI_AGAIN DNS failures in proxy-only environments (corporate networks, containerized sandboxes, Claude Code remote) where Node.js fetch (undici) silently ignores HTTPS_PROXY/HTTP_PROXY env vars
  • Adds undici as an explicit dependency and installs a ProxyAgent as the global fetch dispatcher at startup when any proxy env var is detected (HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy)
  • No behavior change for users without a proxy configured

Closes #83

How it works

A new src/utils/proxy.ts module is imported at the top of src/index.ts (before any fetch() calls). If a proxy env var is present, it calls setGlobalDispatcher(new ProxyAgent(url)), which makes all subsequent fetch() calls route through the proxy automatically.

undici is added as an explicit npm dependency for Node 20 compatibility — node:undici is only available from Node 22+, and the project targets >=20.

Test plan

  • 6 unit tests added in tests/unit/utils/proxy.test.ts covering all four proxy env vars, priority ordering, and the no-proxy case
  • Smoke test: HTTPS_PROXY=http://localhost:9999 node build/index.js produces ECONNREFUSED (proxy attempted) rather than EAI_AGAIN (DNS failure) — confirming proxy routing is active
  • Full replication: run inside a Docker container with --dns=0.0.0.0 (DNS blocked) and a real proxy on the host — traffic routes through the proxy successfully

🤖 Generated with Claude Code

Zack Davis and others added 2 commits April 16, 2026 17:14
Node.js built-in fetch (undici) does not respect HTTP_PROXY/HTTPS_PROXY
environment variables, causing EAI_AGAIN DNS failures in proxy-only
environments (corporate networks, containerized sandboxes, Claude Code remote).

Adds undici as an explicit dependency and installs a ProxyAgent as the
global fetch dispatcher at startup when any proxy env var is detected.

Closes #83

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zdavis-rollbar zdavis-rollbar requested a review from brianr April 16, 2026 22:16
@zdavis-rollbar zdavis-rollbar merged commit a1f4b4c into main Apr 17, 2026
2 checks passed
@zdavis-rollbar zdavis-rollbar deleted the zd/node-https-proxy branch April 17, 2026 13:19
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.

MCP server fails in proxy-only environments (no direct DNS) — Node.js fetch does not respect HTTPS_PROXY

2 participants