feat: honour proxy settings - #66
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
undici doesn't read
HTTP_PROXY/HTTPS_PROXYunless it's given a dispatcher, so requests went direct regardless of the environment. Closes #31.An
EnvHttpProxyAgentis built only when one of those variables is set, so anyone relying onsetGlobalDispatcherkeeps it.options.dispatcheroverrides both, which also covers custom proxies, retries and mocking.Before and after, with
HTTPS_PROXY=http://127.0.0.1:9:The option is typed
unknownrather than undici'sDispatcher. 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.unknownaccepts any agent with no cast at the call site.Supersedes #52.
🤖 Generated with Claude Code