Sec-WebSocket-Extensions header


目录

The HTTP Sec-WebSocket-Extensions request and response header is used in the WebSocket opening handshake to negotiate a protocol extension used by the client and server.

In a request the header specifies one or more extensions that the web application would like to use, in order of preference. These can be added as in multiple headers, or as comma separated values added to a single header. Each extension can also have one or more parameters — these are semicolon-separated values listed after the extension.

In a response the header can only appear once, where it specifies the extension selected by the server from the client's preferences. This value must be the first extension that the server supports from the list provided in the request header.

The request header is automatically added by the browser based on its own capabilities, and does not depend on parameters passed to the constructor when the WebSocket is created.

Header type [Request header](https://developer.mozilla.org/en-US/docs/Glossary/Request%20header), [Response header](https://developer.mozilla.org/en-US/docs/Glossary/Response%20header)
[Forbidden request header](https://developer.mozilla.org/en-US/docs/Glossary/Forbidden%20request%20header) Yes (Sec- prefix)

Syntax

Sec-WebSocket-Extensions: <extensions>

Directives

Examples

WebSocket opening handshake

The HTTP request below shows the opening handshake where a client supports the permessage-deflate extension (with client_max_window_bits parameter), and the bbf-usp-protocol extension.

GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, bbf-usp-protocol

The request below with separate headers for each extension is equivalent:

GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Extensions: bbf-usp-protocol

The response below might be sent from a server to indicate that it will support the permessage-deflate extension:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Extensions: permessage-deflate

Specifications

Browser compatibility

See also


版本号 #3
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 cocobook-sync 更新于 2026-11-04 17:36:06 UTC