Skip to content

fix(fetch): warn when httpVersion is set in the Fetch adapter#10570

Open
JivinSardine wants to merge 1 commit intoaxios:v1.xfrom
JivinSardine:josh/warn-httpVersion-unsupported-fetch
Open

fix(fetch): warn when httpVersion is set in the Fetch adapter#10570
JivinSardine wants to merge 1 commit intoaxios:v1.xfrom
JivinSardine:josh/warn-httpVersion-unsupported-fetch

Conversation

@JivinSardine
Copy link
Copy Markdown

Description

Add a console warning when httpVersion is set in environments using the Fetch adapter (e.g., Bun.js, browser), since the Fetch API does not support the httpVersion option.

Fixes #7535

Problem

When using Bun.js or other browser-like environments, axios uses the Fetch adapter. The httpVersion option is silently ignored in this adapter, which can cause confusion when users expect HTTP/2 behavior.

For example, this config causes requests to hang in Bun.js without any error or warning:

await axios.get(url, {
  maxRedirects: 0,
  httpVersion: 2,
  // ...
});

Solution

Issue a console.warn when httpVersion is set to a non-default value in the Fetch adapter:

Note: The Node.js HTTP adapter (lib/adapters/http.js) already properly handles httpVersion and supports both HTTP/1.1 and HTTP/2.

Checklist

  • The code follows the style guidelines of this project
  • Tests have been added or updated to cover the changes (if applicable)
  • Documentation has been updated to reflect this change (if applicable)
  • The CHANGELOG.md has been updated with a relevant entry

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 1 file

Confidence score: 5/5

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

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Add a console warning when httpVersion is set in environments using the
Fetch adapter (e.g., Bun, browser), since the Fetch API does not
support the httpVersion option.

Fixes axios#7535

When using Bun.js or browser environments, axios silently ignores
the httpVersion option, which can cause confusion when users expect
HTTP/2 behavior. This change issues a clear warning to inform users
that httpVersion is not supported by the Fetch adapter.
@JivinSardine JivinSardine force-pushed the josh/warn-httpVersion-unsupported-fetch branch from b977437 to 7b74905 Compare March 26, 2026 08:20
@DigitalBrainJS
Copy link
Copy Markdown
Collaborator

HTTP/2 is not supported in browser-like environments

Actually, HTTP2 is supported by browsers' fetch, but it's done automatically under the hood, without the ability to select the protocol version manually. As we can see, in the opinion of the fetch spec designers, adding an option to select exactly the protocol version wasn't their priority, so I think the protocol version isn't critical enough for adding a warning to the frontend code, where code size should be reduced at almost any cost. It would be better to highlight this behaviour in the docs rather than adding a notice to the runtime.

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.

http2 not available

2 participants