pub fn upgrade_ws_with_config<H, R, B, E>(
handler: H,
config: WebSocketConfig,
) -> impl Fn(Request<Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
Expand description
Upgrades the http requests to websocket with the provided config.
ยงExamples
use routerify_websocket::{upgrade_ws_with_config, WebSocket, WebSocketConfig};
async fn ws_handler(ws: WebSocket) {
println!("New websocket connection: {}", ws.remote_addr());
// Handle websocket connection.
}
fn router() -> Router<Body, Infallible> {
// Create a router and specify the path and the handler for new websocket connections.
Router::builder()
// Upgrade the http requests at `/ws` path to websocket with the following config.
.any_method("/ws", upgrade_ws_with_config(ws_handler, WebSocketConfig::default()))
.build()
.unwrap()
}