Skip to content

Sec-WebSocket-Protocol

In requests, this header indicates the sub-protocols supported by the client in preferred order. In responses, it indicates the sub-protocol selected by the server from the client’s preferences.

The Sec-WebSocket-Protocol HTTP header is a specialized field used to in requests, this header indicates the sub-protocols supported by the client in preferred order. In responses, it indicates the sub-protocol selected by the server from the client’s preferences. It acts as a signaling mechanism between the client and the server to enforce policies, negotiate capabilities, or provide telemetry data during the transmission of requests and responses.

This header is primarily utilized when the server needs to govern the response behavior. Modern web applications rely on this to maintain state and context.

It facilitates seamless programmatic integration by ensuring both the client and server agree on the terms of the transaction, greatly improving performance, security, and rendering correctness without manual user intervention.

Implement or parse this header within your application’s network layer (such as an Express middleware or a Next.js edge function) by reading or attaching the key-value pair:

Sec-WebSocket-Protocol: <appropriate-value>
Sec-WebSocket-Protocol: <value>