Skip to main content

Module ws_proxy

Module ws_proxy 

Source
Expand description

WebSocket reverse proxy.

WsProxy listens for incoming TCP connections, reads the initial HTTP request, verifies it is a WebSocket upgrade, connects to a backend, performs the WebSocket handshake end-to-end, and then bidirectionally tunnels raw WebSocket bytes between the client and the backend.

Two threads handle each live connection (one per direction), so neither side is blocked waiting for the other.

§Example

use rust_web_server::ws_proxy::WsProxy;

// All WebSocket connections on port 8080 are forwarded to a chat backend.
WsProxy::new(["chat-backend:9000", "chat-backend:9001"])
    .connect_timeout_ms(3000)
    .bind("0.0.0.0:8080")
    .unwrap();

Structs§

WsProxy
WebSocket reverse proxy with round-robin load balancing.