WebSocket Proxy

The WebSocket Proxy module for Edge Application allows you to establish the WebSocket communication protocol between your origin and your users under the reverse proxy architecture. This type of protocol consists of a single bidirectional TCP connection that allows data to be exchanged in real time via a single handshake without the need to restart the connection.

WebSockets are designed to minimize latency and increase efficiency, and are suitable for applications that exchange data in real time, such as online games, chat platforms, notifications, and live streaming services. See the WebSocket protocol specification for more information.

Due to their nature as a bidirectional open connection, WebSocket Proxy is incompatible with the use of the Edge Functions and Image Processor modules. WebSocket connections won’t work in conjunction with Edge Cache or Tiered Cache.

Edge Application first stepsFirst steps

Your client and server must support the WebSocket connection natively for the protocol to be implemented in your edge applications. On the client side, most browsers include native WebSocket support. See the complete list of browsers with WebSocket support.

The origin application must inject the Upgrade: websocket and Connection: upgrade HTTP headers for the connection to be successfully established. If the Connection and Upgrade headers are sent by the client with values other than those specified above or one of them isn’t present, the connection upgrade in the user request to the origin won’t be carried out.

By default, an edge application that has the WebSocket Proxy module enabled will consider any request received with the headers Upgrade: websocket and Connection: upgrade to be a websocket connection and will forward them to the origin. It’s recommended that the application itself controls the headers in cases where the protocol should be used.

A valid WebSocket connection will return the status 101 Switching Protocols. If this isn’t the status received, even if it’s among the 2xx or 3xx family of success statuses, it’s likely that the client request, the edge application, or the origin server didn’t complete the Websocket connection. In this case, you should review the connection upgrade requirements and make the necessary adjustments.

These are the default limits:

Maximum connection time¹15 minutes

¹ Azion recycles keepalive connections on its servers approximately every 15 minutes. Active WebSocket connections may be terminated if they exceed this range. In such cases, your application should handle these scenarios and reestablish the connection as needed.