🔌 trillium-websockets — WebSocket handler
WebSocket handler for Trillium, built on async-tungstenite. Accepts WebSocket upgrade requests and hands each connection to an async handler function or a WebSocketHandler implementation. Optionally supports the json feature for typed JSON message handling via JsonWebSocketHandler.
Example
use StreamExt;
use ;
let app = websocket;
// run with your chosen runtime adapter, e.g.:
// trillium_tokio::run(app);
Origin checking
Browsers do not apply CORS to websocket handshakes, so by default this handler accepts a handshake
only if its Origin names the same host as the request's Host/:authority, or if there is no
Origin at all (a non-browser client). Rejected handshakes receive a 403 Forbidden.
use ;
# let handler = ;
websocket.allow_origins;
allow_origin_fn takes a predicate over the raw header for cases like a family of subdomains, and
allow_any_origin opts out entirely.
Safety
This crate uses #![forbid(unsafe_code)].