Switching protocols mid-connection
Modern HTTP can negotiate a better protocol — HTTP/2, HTTP/3 or WebSocket —
after a connection starts. The Upgrade mechanism switches the current
connection in place and returns 101 Switching Protocols, while Alt-Svc
points the client at an alternative endpoint to use on future requests. This
reference covers those headers plus the TLS ALPN extension that actually drives
h2/h3 selection in browsers, with a parser for any Alt-Svc value.
How it works
An Alt-Svc value is a comma-separated list of alternative services, each with
a protocol id, an authority and optional parameters:
Alt-Svc: h3=":443"; ma=86400; persist=1, h2="alt.example.com:443"; ma=3600
Here h3 (HTTP/3 over QUIC) is offered on port 443 of the same host for one day
and persisted across network changes, while h2 points to a different host. The
parser splits each entry and reads its ma (max-age) and persist flag. The
classic Upgrade flow is different — it is hop-by-hop and switches the live
connection:
GET /chat HTTP/1.1
Connection: Upgrade
Upgrade: websocket
→ HTTP/1.1 101 Switching Protocols
In browsers, HTTP/2 and HTTP/3 are chosen during the TLS handshake via ALPN, so
Upgrade survives mainly for WebSocket and Alt-Svc for steering to QUIC.
Tips and notes
Connection: Upgrademust accompanyUpgrade, or proxies will forward it incorrectly.- An empty host in
Alt-Svc(h3=":443") means the same host on that port. madefaults to 24 hours;persist=1keeps the alternative across network changes.- Cleartext
h2cupgrades are unused on the web — rely on ALPN andAlt-Svc.