Skip to content

feat: honour proxy settings - #66

Merged
iamtraction merged 3 commits into
masterfrom
fix/proxy-support
Aug 4, 2026
Merged

feat: honour proxy settings#66
iamtraction merged 3 commits into
masterfrom
fix/proxy-support

Conversation

@iamtraction

Copy link
Copy Markdown
Owner

undici doesn't read HTTP_PROXY/HTTPS_PROXY unless it's given a dispatcher, so requests went direct regardless of the environment. Closes #31.

An EnvHttpProxyAgent is built only when one of those variables is set, so anyone relying on setGlobalDispatcher keeps it. options.dispatcher overrides both, which also covers custom proxies, retries and mocking.

Before and after, with HTTPS_PROXY=http://127.0.0.1:9:

master:  reached Google, proxy IGNORED -> hello
branch:  routed via proxy, failed as expected -> connect ECONNREFUSED 127.0.0.1:9

The option is typed unknown rather than undici's Dispatcher. Importing that type pulls in undici's whole type surface, which requires @types/node — consumers type-checking without it would get errors out of this package. unknown accepts any agent with no cast at the call site.

Supersedes #52.

🤖 Generated with Claude Code

iamtraction and others added 3 commits August 5, 2026 04:14
undici does not read HTTP_PROXY or HTTPS_PROXY unless it is given a dispatcher,
so requests went direct regardless of the environment. Closes #31.

An EnvHttpProxyAgent is built only when one of those variables is set, so
anyone relying on setGlobalDispatcher keeps it. options.dispatcher overrides
both, which also covers custom proxies, retries and mocking.

The option is typed as unknown rather than undici's Dispatcher: importing that
type pulls in undici's whole surface, which needs @types/node, and consumers
type checking without it would get errors out of this package.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
EnvHttpProxyAgent resolves the proxy URLs in its constructor, so caching one
instance pinned whichever proxy was set first: pointing HTTP_PROXY at a second
proxy kept routing through the first. Confusingly NO_PROXY was still honoured
live, as undici re-reads that one. The agent is now keyed on the variables it
was built from.

Passing the dispatcher is also unconditional, as undici falls back to the
global dispatcher when it is undefined, so the two request paths no longer
spell the same decision differently.

The typed option becomes a structural Dispatcher rather than unknown, which
keeps the README honest without pulling in undici's types and their @types/node
requirement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Both branches changed the requires at the top of src/index.js: #65 dropped the
querystring module, this one added EnvHttpProxyAgent. Resolved by keeping the
undici import with both names and leaving querystring out, so the query is
still built by the stringify helper from #65.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@iamtraction
iamtraction merged commit 3d04e09 into master Aug 4, 2026
2 checks passed
@iamtraction
iamtraction deleted the fix/proxy-support branch August 4, 2026 22:53
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.

didn't work behind proxy

1 participant