async fn server_upgrade(req: Request<Body>) -> Result<Response<Body>, io::Error> {
    debug!("We got these headers: {:?}", req.headers());

    Ok(ws::spawn_websocket_with_timeout(
        req,
        |m| {
            Box::pin(async move {
                debug!("Got message {:?}", m);
                let counter: u64 = {
                    let mut c = m.context_ref().write().await;
                    *c = *c + 1;
                    *c
                };

                Ok(Some(ws::Message::text(
                    format!("{}: {}", counter, m.to_str().unwrap()),
                    m.context(),
                )))
            })
        },
        Duration::from_secs(5 * 60),
    ))
}
/// Our server HTTP handler to initiate HTTP upgrades.
Our server HTTP handler to initiate HTTP upgrades.
Our server HTTP handler to initiate HTTP upgrades .
async fn server_upgrade(req: Request<Body>) -> Result<Response<Body>, io::Error> {
    debug!("We got these headers: {:?}", req.headers());
    Ok(ws::spawn_websocket_with_timeout(
        req,
        |m| {
            Box::pin(async move {
                debug!("Got message {:?}", m);
                let counter: u64 = {
                    let mut c = m.context_ref().write().await;
                    *c = *c + 1;
                    *c
                };
                Ok(Some(ws::Message::text(
                    format!("{}: {}", counter, m.to_str().unwrap()),
                    m.context(),
                )))
            })
        },
        Duration::from_secs(5 * 60),
    ))
}
async fn server_upgrade ( req : Request < Body > ) -> Result < Response < Body > , io :: Error > { debug ! ( " " req headers ( ) ) ; Ok ( ws :: spawn_websocket_with_timeout ( req , | m | { Box :: pin ( async move { debug ! ( " " m ) ; let counter : u64 = { let mut c = m . context_ref ( ) . write ( ) . await ; * c = * c + 1 ; * c } ; Ok ( Some ( ws :: Message :: text ( format ! ( " " counter m to_str ( ) unwrap ( ) ) , m . context ( ) , ) ) ) } ) } , Duration :: from_secs ( 5 * 60 ) , ) ) }
Our server HTTP handler to initiate HTTP upgrades.
Our server HTTP handler to initiate HTTP upgrades .
req
Request<Body>
req
Request<Body>