How Axios Handles HTTP/2 and HTTP/3 Requests
Axios handles HTTP/2 and HTTP/3 network requests differently depending on its runtime environment: the browser or Node.js. In web browsers, Axios delegates network operations to the browser's underlying engine, which automatically supports HTTP/2 and HTTP/3 transparently. In Node.js, Axios relies on native core modules that default strictly to HTTP/1.1, requiring third-party adapters or custom transport layers to enable HTTP/2, while native HTTP/3 support remains currently unavailable.
Axios in the Browser
When running inside a browser environment, Axios uses the
XMLHttpRequest interface (or the fetch API if
configured with a custom adapter).
- Transparent Protocol Negotiation: The browser manages the transport layer, utilizing Application-Layer Protocol Negotiation (ALPN) during the TLS handshake.
- Automatic Upgrades: If the destination server supports HTTP/2 or HTTP/3 (QUIC), the browser automatically negotiates and uses these protocols.
- Feature Inheritance: Features like stream multiplexing, header compression (HPACK/QPACK), and connection reuse happen at the browser level without requiring configuration changes in Axios.
From the developer's perspective in the browser, Axios code remains identical regardless of whether the underlying connection is HTTP/1.1, HTTP/2, or HTTP/3.
Axios in Node.js
In a Node.js environment, Axios behaves differently because it directly interfaces with Node's low-level networking APIs.
- Default HTTP/1.1 Behavior: Axios uses Node.js's
standard
httpandhttpsmodules by default. These modules only support HTTP/1.1 and HTTP/1.0, meaning Axios cannot establish HTTP/2 or HTTP/3 connections out of the box. - No Automatic ALPN Negotiation: Unlike modern
browsers, Node's
httpsmodule does not automatically upgrade connections to HTTP/2 via ALPN when communicating with compatible servers.
Enabling HTTP/2 Support in Node.js
To process HTTP/2 requests using Axios in Node.js, you must bypass the default HTTP/1.1 adapter and implement an HTTP/2-compatible transport layer.
- Custom Adapters: You can supply a custom
adapterto Axios using packages likehttp2-wrapperor Node’s nativehttp2module. - Agent Compatibility: Because standard
http.Agentinstances are incompatible with HTTP/2 sessions, the custom transport must manage HTTP/2 session lifecycles, stream multiplexing, and fallback mechanisms for servers that only support HTTP/1.1.
The Status of HTTP/3 (QUIC) in Axios
HTTP/3 relies on the QUIC transport protocol over UDP instead of TCP.
- Node.js Limitations: Stable releases of Node.js do not yet provide full, production-ready native HTTP/3 client APIs. As a result, Axios cannot process HTTP/3 requests in Node.js.
- Browser Usage: In browsers, Axios will utilize
HTTP/3 automatically if the client browser supports QUIC, the server
advertises HTTP/3 availability (typically via the
Alt-Svcheader), and UDP traffic is not blocked by network firewalls.