Skip to main content

Upgrade

BothActive

The Upgrade header allows the client to request a protocol switch on an existing connection – most commonly used to upgrade HTTP/1.1 to WebSocket. The server responds with 101 Switching Protocols if it accepts the upgrade. HTTPS connections use ALPN for HTTP/2 negotiation instead; Upgrade is only for HTTP/1.1.

Upgrade: websocket | h2c | TLS/1.3

Description

Upgrade is the HTTP/1.1 mechanism for protocol negotiation. A WebSocket handshake uses Upgrade: websocket with a Sec-WebSocket-Key. The server validates the key and returns 101. Once upgraded, the connection is no longer HTTP – it uses the WebSocket framing protocol. Upgrade cannot be used over HTTP/2.

Directives

DirectiveDescription
websocketUpgrade to WebSocket protocol. Requires Sec-WebSocket-Key and Sec-WebSocket-Version.
h2cUpgrade to HTTP/2 over cleartext. Rarely used – HTTP/2 normally requires TLS.

Examples

WebSocket upgrade request
http
GET /chat HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Server accepts upgrade
http
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

Related

Specification

RFC 9110Upgrade specification →