WebSocket Proxy
Look up what WebSocket Proxy needs in an Application, the upgrade headers, the errors it returns, and its connection limits.
WebSocket is a protocol, specified in RFC 6455, that keeps one TCP connection open in both directions between a client and a server. After one handshake, both sides exchange data over it in real time. WebSocket Proxy is a Feature of Applications that carries that connection between your users and your origin. The connection passes through an Application that acts as a reverse proxy for that origin. Use WebSocket Proxy for real-time applications such as online games, chat, notifications, and live streaming.
WebSocket Proxy fits when the WebSocket server is your origin, because the Application only carries the connection to it. When a Function should act as the WebSocket server or client itself, use the WebSocket API instead, which handles a server-side upgrade with upgradeWebSocket().
Availability
Azion turns WebSocket Proxy on for an account only on request. To request it, refer to Support guidelines.
Client and origin support
A WebSocket connection through an Application needs native WebSocket support at both ends: the client that opens the connection and the server at the origin. Most browsers support WebSocket natively. For the list of browsers with native support, refer to Can I use.
Upgrade headers
An Application with WebSocket Proxy enabled reads two request headers to decide whether a request opens a WebSocket connection. It treats the request as one, and proxies it to the origin, when Upgrade reads websocket and Connection carries the upgrade token, in any letter case, alone or in a list such as Connection: keep-alive, Upgrade.
| Header | Value |
|---|---|
Upgrade |
websocket |
Connection |
upgrade |
When the client omits either header, or sends a value that does not name the upgrade, the Application does not carry out the upgrade toward the origin.
The rules of a Firewall, in Rules Engine for Firewall, can inspect a WebSocket request before the upgrade completes.
Errors
A WebSocket connection through an Application completes with 101 Switching Protocols. Any other status means that the upgrade did not complete, even a 2xx success or a 3xx redirection:
| Status | Cause | What to do |
|---|---|---|
Any status other than 101 |
The client, the Application, or the origin did not complete the WebSocket connection | Check the client, the origin, and the upgrade headers |
The client and the origin both need native WebSocket support, and the request needs both upgrade headers with their values.
Limits
Azion recycles keepalive connections on its servers approximately every 15 minutes, and it can terminate an active WebSocket connection that stays open past that time. Your application then needs to detect the closed connection and reestablish it. For the maximum connection time of a WebSocket connection, and how to request a higher limit for your plan, refer to Applications limits.