pub async fn start_with<T, F, Err>(
    req: HttpRequest,
    factory: F,
) -> Result<HttpResponse, Err>
where
    T: ServiceFactory<DispatchItem<ws::Codec>, WsSink, Response = Option<Message>>
        + 'static,
    T::Error: fmt::Debug,
    F: IntoServiceFactory<T, DispatchItem<ws::Codec>, WsSink>,
    Err: From<T::InitError> + From<HandshakeError>,
{
    log::trace!("Start ws handshake verification for {:?}", req.path());

    // ws handshake
    let res = handshake(req.head())?.finish().into_parts().0;

    // extract io
    let item = req
        .head()
        .take_io()
        .ok_or(HandshakeError::NoWebsocketUpgrade)?;
    let io = item.0;
    let codec = item.1;

    io.encode(h1::Message::Item((res, BodySize::Empty)), &codec)
        .map_err(|_| HandshakeError::NoWebsocketUpgrade)?;
    log::trace!("Ws handshake verification completed for {:?}", req.path());

    // create sink
    let codec = ws::Codec::new();
    let sink = WsSink::new(io.get_ref(), codec.clone());

    // create ws service
    let srv = factory.into_factory().new_service(sink).await?;

    // start websockets service dispatcher
    rt::spawn(async move {
        let res = crate::io::Dispatcher::new(io, codec, srv)
            .keepalive_timeout(Seconds::ZERO)
            .await;
        log::trace!("Ws handler is terminated: {:?}", res);
    });

    Ok(HttpResponse::new(StatusCode::OK))
}
/// Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service .
pub async fn start_with<T, F, Err>(
    req: HttpRequest,
    factory: F,
) -> Result<HttpResponse, Err>
where
    T: ServiceFactory<DispatchItem<ws::Codec>, WsSink, Response = Option<Message>>
        + 'static,
    T::Error: fmt::Debug,
    F: IntoServiceFactory<T, DispatchItem<ws::Codec>, WsSink>,
    Err: From<T::InitError> + From<HandshakeError>,
{
    log::trace!("Start ws handshake verification for {:?}", req.path());
    // ws handshake
    let res = handshake(req.head())?.finish().into_parts().0;
    // extract io
    let item = req
        .head()
        .take_io()
        .ok_or(HandshakeError::NoWebsocketUpgrade)?;
    let io = item.0;
    let codec = item.1;
    io.encode(h1::Message::Item((res, BodySize::Empty)), &codec)
        .map_err(|_| HandshakeError::NoWebsocketUpgrade)?;
    log::trace!("Ws handshake verification completed for {:?}", req.path());
    // create sink
    let codec = ws::Codec::new();
    let sink = WsSink::new(io.get_ref(), codec.clone());
    // create ws service
    let srv = factory.into_factory().new_service(sink).await?;
    // start websockets service dispatcher
    rt::spawn(async move {
        let res = crate::io::Dispatcher::new(io, codec, srv)
            .keepalive_timeout(Seconds::ZERO)
            .await;
        log::trace!("Ws handler is terminated: {:?}", res);
    });
    Ok(HttpResponse::new(StatusCode::OK))
}
pub async fn start_with < T , F , Err > ( req : HttpRequest , factory : F , ) -> Result < HttpResponse , Err > where T : ServiceFactory < DispatchItem < ws :: Codec > , WsSink , Response = Option < Message > > + ' static , T :: Error : fmt :: Debug , F : IntoServiceFactory < T , DispatchItem < ws :: Codec > , WsSink > , Err : From < T :: InitError > + From < HandshakeError > , { log :: trace ! ( " " req path ( ) ) ; // ws handshake let res = handshake ( req . head ( ) ) ? . finish ( ) . into_parts ( ) . 0 ; // extract io let item = req . head ( ) . take_io ( ) . ok_or ( HandshakeError :: NoWebsocketUpgrade ) ? ; let io = item . 0 ; let codec = item . 1 ; io . encode ( h1 :: Message :: Item ( ( res , BodySize :: Empty ) ) , & codec ) . map_err ( | _ | HandshakeError :: NoWebsocketUpgrade ) ? ; log :: trace ! ( " " req path ( ) ) ; // create sink let codec = ws :: Codec :: new ( ) ; let sink = WsSink :: new ( io . get_ref ( ) , codec . clone ( ) ) ; // create ws service let srv = factory . into_factory ( ) . new_service ( sink ) . await ? ; // start websockets service dispatcher rt :: spawn ( async move { let res = crate :: io :: Dispatcher :: new ( io , codec , srv ) . keepalive_timeout ( Seconds :: ZERO ) . await ; log :: trace ! ( " " res ) ; } ) ; Ok ( HttpResponse :: new ( StatusCode :: OK ) ) }
Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service .
req
HttpRequest
factory
F
req
HttpRequest
factory
F