Skip to main content

proxy_websocket

Function proxy_websocket 

Source
pub async fn proxy_websocket(
    req: Request<Body>,
    upstream_addr: &str,
) -> Result<Response<Body>, ProxyError>
Expand description

Proxy a WebSocket upgrade request to the given upstream address.

The flow:

  1. Open a raw TCP connection to the upstream.
  2. Write the HTTP upgrade request to the upstream.
  3. Read the upstream’s 101 response.
  4. Return a 101 response to the client (with the upgrade extension on the hyper side).
  5. Once both sides have upgraded, spawn a task that copies bytes bidirectionally until either side closes.