fix(fetch-adapter): set User-Agent header to match http adapter#10772
Merged
jasonsaayman merged 2 commits intoaxios:v1.xfrom Apr 26, 2026
Merged
fix(fetch-adapter): set User-Agent header to match http adapter#10772jasonsaayman merged 2 commits intoaxios:v1.xfrom
jasonsaayman merged 2 commits intoaxios:v1.xfrom
Conversation
The fetch adapter was not setting a User-Agent header, causing requests to use Node.js's default 'node' user agent instead of 'axios/<version>'. This mirrors the existing behavior in the HTTP adapter. Fixes axios#7494
c2e53cf to
6e541db
Compare
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
The fetch adapter does not set a
User-Agentheader, causing requests to appear with Node.js's defaultnodeuser agent instead ofaxios/<version>. The HTTP adapter correctly sets this header.Content-Length,Accept-Encoding,Host, andConnectionare intentionally not added — these are forbidden headers managed automatically by the Fetch API (see maintainer feedback on #10633).Fixes #7494
Changes
lib/adapters/fetch.js: setUser-Agent: axios/<version>header, mirroring the HTTP adapter, with a no-override guard for user-supplied valuesChecklist
Summary by cubic
Sets the fetch adapter’s default
User-Agenttoaxios/<version>to match the Node HTTP adapter and avoid Node’s defaultnodeUA. Keeps any user-providedUser-Agentintact.Description
User-Agent: axios/<version>in thefetchadapter with a no-override guard.v1.xinto the branch; no behavior changes.nodeUA. Fixes Fetch Adapter: Content length header is missing in POST request #7494.Content-Length,Accept-Encoding,Host, orConnection(managed by Fetch and forbidden to set).Docs
/docs/to document the fetch adapter’s defaultUser-Agent, how to override it, and parity with the HTTP adapter.Testing
User-Agenttoaxios/<version>by default.User-Agent.Semantic version impact
Written for commit d7e0817. Summary will update on new commits.