Sec-WebSocket-Version header

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The HTTP Sec-WebSocket-Version request and response header is used in the WebSocket opening handshake to indicate the WebSocket protocol supported by the client, and the protocol versions supported by the server if it does not support the version specified in the request.

The header can only appear once in a request, and specifies the WebSocket version that web application is using. The current version of the protocol at time of writing is 13. The header is automatically added to requests by user agents when a WebSocket connection is established.

The server uses the version to determine if it can understand the protocol. If the server doesn't support the version, or any header in the handshake is not understood or has an incorrect value, the server should send a response with status 400 Bad Request and immediately close the socket. It should also include Sec-WebSocket-Version in the 400 response, listing the versions that it does support. The versions can be specified in individual headers, or as comma-separate values in a single header.

The header should not be sent in responses if the server understands the version specified by the client.

Header type Response header
Forbidden request header Yes (Sec- prefix)

Syntax

Request

http
Sec-WebSocket-Version: <version>

Response (on error only):

http
Sec-WebSocket-Version: <server-supported-versions>

Directives

<version>

The WebSocket protocol version the client wishes to use when communicating with the server. This number should be the most recent version possible listed in the IANA WebSocket Version Number Registry. The most recent final version of the WebSocket protocol is version 13.

<server-supported-versions>

On error, a comma-delineated list of the WebSocket protocol versions supported by the server. The header is not sent in responses if <version> is supported.

Examples

WebSocket opening handshake

The version supported by the client is specified in the original WebSocket handshake request. For the current protocol, the version is "13", as shown below.

http
GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13

If the server supports version 13 of the protocol, then Sec-WebSocket-Version will not appear in the response.

Specifications

Specification
The WebSocket Protocol
# section-11.3.5

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Sec-WebSocket-Version
Chrome – Full support
Chrome 16 (Release date: 2011-12-13)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 11 (Release date: 2012-03-13)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 6 (Release date: 2012-07-25)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 14 (Release date: 2012-06-26)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 6 (Release date: 2012-09-10)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also