Skip to content

fix(fetch-adapter): set User-Agent header to match http adapter#10772

Merged
jasonsaayman merged 2 commits intoaxios:v1.xfrom
OfekDanny:fix/fetch-adapter-user-agent
Apr 26, 2026
Merged

fix(fetch-adapter): set User-Agent header to match http adapter#10772
jasonsaayman merged 2 commits intoaxios:v1.xfrom
OfekDanny:fix/fetch-adapter-user-agent

Conversation

@OfekDanny
Copy link
Copy Markdown
Contributor

@OfekDanny OfekDanny commented Apr 20, 2026

Summary

The fetch adapter does not set a User-Agent header, causing requests to appear with Node.js's default node user agent instead of axios/<version>. The HTTP adapter correctly sets this header.

Content-Length, Accept-Encoding, Host, and Connection are 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: set User-Agent: axios/<version> header, mirroring the HTTP adapter, with a no-override guard for user-supplied values

Checklist

  • Code follows axios style conventions
  • Tests added/updated
  • Conventional commit message used

Summary by cubic

Sets the fetch adapter’s default User-Agent to axios/<version> to match the Node HTTP adapter and avoid Node’s default node UA. Keeps any user-provided User-Agent intact.

Description

  • Summary of changes
    • Set User-Agent: axios/<version> in the fetch adapter with a no-override guard.
    • Merged latest v1.x into the branch; no behavior changes.
  • Reasoning
  • Additional context
    • Did not add Content-Length, Accept-Encoding, Host, or Connection (managed by Fetch and forbidden to set).

Docs

  • Update /docs/ to document the fetch adapter’s default User-Agent, how to override it, and parity with the HTTP adapter.

Testing

  • Added unit tests:
    • Sets User-Agent to axios/<version> by default.
    • Does not override a user-provided User-Agent.
  • No further tests needed.

Semantic version impact

  • Patch: bug fix aligning adapter behavior without breaking the API.

Written for commit d7e0817. Summary will update on new commits.

@OfekDanny OfekDanny requested a review from jasonsaayman as a code owner April 20, 2026 08:23
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

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
@OfekDanny OfekDanny force-pushed the fix/fetch-adapter-user-agent branch from c2e53cf to 6e541db Compare April 23, 2026 08:37
@jasonsaayman jasonsaayman merged commit c918e85 into axios:v1.x Apr 26, 2026
35 of 37 checks passed
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.

Fetch Adapter: Content length header is missing in POST request

3 participants