fn handle_ws_connection(req: Request<Body>) -> Result<Response<Body>, io::Error> {
    let res = match upgrade_connection(req) {
        Err(res) => res,
        Ok((res, ws)) => {
            let run_ws_task = async {
                match ws.await {
                    Ok(ws) => {
                        debug!("Spawning WS");
                        let mut counter = 0;
                        let (tx, rc) = ws.split();
                        let rc = rc.try_filter_map(|m| {
                            debug!("Got message {:?}", m);
                            future::ok(match m {
                                protocol::Message::Text(text) => {
                                    counter += 1;
                                    Some(protocol::Message::text(format!(
                                        "Response {}: {}",
                                        counter, text
                                    )))
                                }
                                _ => None,
                            })
                        });
                        match rc.forward(tx).await {
                            Err(e) => error!("WS Error {}", e),
                            Ok(_) => debug!("Websocket has ended"),
                        }
                    }
                    Err(_e) => error!("WS error"),
                }
            };
            tokio::spawn(run_ws_task);
            res
        }
    };
    debug!("WS HTTP Response {:?}", res);
    Ok(res)
}
// Just echo back received messages.
Just echo back received messages.
Just echo back received messages .
fn handle_ws_connection(req: Request<Body>) -> Result<Response<Body>, io::Error> {
    let res = match upgrade_connection(req) {
        Err(res) => res,
        Ok((res, ws)) => {
            let run_ws_task = async {
                match ws.await {
                    Ok(ws) => {
                        debug!("Spawning WS");
                        let mut counter = 0;
                        let (tx, rc) = ws.split();
                        let rc = rc.try_filter_map(|m| {
                            debug!("Got message {:?}", m);
                            future::ok(match m {
                                protocol::Message::Text(text) => {
                                    counter += 1;
                                    Some(protocol::Message::text(format!(
                                        "Response {}: {}",
                                        counter, text
                                    )))
                                }
                                _ => None,
                            })
                        });
                        match rc.forward(tx).await {
                            Err(e) => error!("WS Error {}", e),
                            Ok(_) => debug!("Websocket has ended"),
                        }
                    }
                    Err(_e) => error!("WS error"),
                }
            };
            tokio::spawn(run_ws_task);
            res
        }
    };
    debug!("WS HTTP Response {:?}", res);
    Ok(res)
}
fn handle_ws_connection ( req : Request < Body > ) -> Result < Response < Body > , io :: Error > { let res = match upgrade_connection ( req ) { Err ( res ) => res , Ok ( ( res , ws ) ) => { let run_ws_task = async { match ws . await { Ok ( ws ) => { debug ! ( " " ) ; let mut counter = 0 ; let ( tx , rc ) = ws . split ( ) ; let rc = rc . try_filter_map ( | m | { debug ! ( " " m ) ; future :: ok ( match m { protocol :: Message :: Text ( text ) => { counter += 1 ; Some ( protocol :: Message :: text ( format ! ( " " counter text ) ) ) } _ => None , } ) } ) ; match rc . forward ( tx ) . await { Err ( e ) => error ! ( " " e ) , Ok ( _ ) => debug ! ( " " ) , } } Err ( _e ) => error ! ( " " ) , } } ; tokio :: spawn ( run_ws_task ) ; res } } ; debug ! ( " " res ) ; Ok ( res ) }
Just echo back received messages.
Just echo back received messages .
req
Request<Body>
req
Request<Body>