fix(http): preserve user-supplied Host header when forwarding through a proxy (#10805)#10822
Merged
jasonsaayman merged 4 commits intoaxios:v1.xfrom Apr 30, 2026
Conversation
… a proxy (axios#10805) When sending a request through a proxy with the http adapter, axios was unconditionally rewriting `options.headers.host` to the request URL's hostname:port, overwriting any Host header the caller had set in `config.headers`. This made it impossible to direct a proxy to a virtual host that differs from the request URL — for example, hitting `127.0.0.1:4000` while asking the proxy to treat the request as `example.com`. Skip the default assignment when a Host header is already present (case-insensitive match, since users may pass `host`, `Host`, or `HOST`).
Contributor
Author
|
@jasonsaayman can you pls review this |
jasonsaayman
approved these changes
Apr 30, 2026
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.
Summary
Fixes #10805.
When sending a request through a proxy with the http adapter, axios was unconditionally rewriting
options.headers.hostto the request URL'shostname:port, overwriting anyHostheader the caller had set inconfig.headers. That made it impossible to direct a proxy to a virtual host that differs from the request URL.Before
The proxy received:
After
The proxy receives:
Change
In
lib/adapters/http.js#setProxy, only assign the defaultHostheader when the caller has not already provided one. The check is case-insensitive so users can passhost,Host, orHOST.Test plan
tests/unit/adapters/http.test.jscovering the default behavior, lowercase user header, and mixed-case user header (Host header preservation when forwarding through a proxy (#10805)describe block).vitest run --project unit -t "proxy"— 46 passed).Hostvalue while the target still sees its own hostname.Summary by cubic
Preserves a user-supplied Host header when requests go through a proxy in the Node http adapter for
axios. This lets callers route to virtual hosts via proxies without the header being overwritten.Description
options.headers.hostif the user already set anyHost/hostheader (case-insensitive). Otherwise default tohostname:port.Docs
Please update
/docs/to note thataxiosrespects a user-suppliedHostheader when using a proxy, with a short example showing virtual host routing via proxies.Testing
Hostis provided.hostand mixed-caseHost.Host.Semantic version impact
Patch (bug fix, no API changes).
Written for commit 584f284. Summary will update on new commits. Review in cubic