async fn hyper_service_fn(
    rocket: Arc<Rocket<Orbit>>,
    h_addr: std::net::SocketAddr,
    hyp_req: hyper::Request<hyper::Body>,
) -> Result<hyper::Response<hyper::Body>, io::Error> {
    // This future must return a hyper::Response, but the response body might
    // borrow from the request. Instead, write the body in another future that
    // sends the response metadata (and a body channel) prior.
    let (tx, rx) = oneshot::channel();

    tokio::spawn(async move {
        // Get all of the information from Hyper.
        let (h_parts, h_body) = hyp_req.into_parts();

        // Convert the Hyper request into a Rocket request.
        let req_res = Request::from_hyp(
            &rocket, h_parts.method, h_parts.headers, &h_parts.uri, h_addr
        );

        let mut req = match req_res {
            Ok(req) => req,
            Err(e) => {
                error!("Bad incoming request: {}", e);
                // TODO: We don't have a request to pass in, so we just
                // fabricate one. This is weird. We should let the user know
                // that we failed to parse a request (by invoking some special
                // handler) instead of doing this.
                let dummy = Request::new(&rocket, Method::Get, Origin::dummy());
                let r = rocket.handle_error(Status::BadRequest, &dummy).await;
                return rocket.send_response(r, tx).await;
            }
        };

        // Retrieve the data from the hyper body.
        let mut data = Data::from(h_body);

        // Dispatch the request to get a response, then write that response out.
        let token = rocket.preprocess_request(&mut req, &mut data).await;
        let r = rocket.dispatch(token, &mut req, data).await;
        rocket.send_response(r, tx).await;
    });

    // Receive the response written to `tx` by the task above.
    rx.await.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
}
// This function tries to hide all of the Hyper-ness from Rocket. It essentially
// converts Hyper types into Rocket types, then calls the `dispatch` function,
// which knows nothing about Hyper. Because responding depends on the
// `HyperResponse` type, this function does the actual response processing.
This function tries to hide all of the Hyper-ness from Rocket. It essentially
converts Hyper types into Rocket types, then calls the `dispatch` function,
which knows nothing about Hyper. Because responding depends on the
`HyperResponse` type, this function does the actual response processing.
This function tries to hide all of the Hyper - ness from Rocket . It essentially converts Hyper types into Rocket types then calls the ` dispatch ` function which knows nothing about Hyper . Because responding depends on the ` HyperResponse ` type this function does the actual response processing .
async fn hyper_service_fn(
    rocket: Arc<Rocket<Orbit>>,
    h_addr: std::net::SocketAddr,
    hyp_req: hyper::Request<hyper::Body>,
) -> Result<hyper::Response<hyper::Body>, io::Error> {
    // This future must return a hyper::Response, but the response body might
    // borrow from the request. Instead, write the body in another future that
    // sends the response metadata (and a body channel) prior.
    let (tx, rx) = oneshot::channel();
    tokio::spawn(async move {
        // Get all of the information from Hyper.
        let (h_parts, h_body) = hyp_req.into_parts();
        // Convert the Hyper request into a Rocket request.
        let req_res = Request::from_hyp(
            &rocket, h_parts.method, h_parts.headers, &h_parts.uri, h_addr
        );
        let mut req = match req_res {
            Ok(req) => req,
            Err(e) => {
                error!("Bad incoming request: {}", e);
                // TODO: We don't have a request to pass in, so we just
                // fabricate one. This is weird. We should let the user know
                // that we failed to parse a request (by invoking some special
                // handler) instead of doing this.
                let dummy = Request::new(&rocket, Method::Get, Origin::dummy());
                let r = rocket.handle_error(Status::BadRequest, &dummy).await;
                return rocket.send_response(r, tx).await;
            }
        };
        // Retrieve the data from the hyper body.
        let mut data = Data::from(h_body);
        // Dispatch the request to get a response, then write that response out.
        let token = rocket.preprocess_request(&mut req, &mut data).await;
        let r = rocket.dispatch(token, &mut req, data).await;
        rocket.send_response(r, tx).await;
    });
    // Receive the response written to `tx` by the task above.
    rx.await.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
}
async fn hyper_service_fn ( rocket : Arc < Rocket < Orbit > > , h_addr : std :: net :: SocketAddr , hyp_req : hyper :: Request < hyper :: Body > , ) -> Result < hyper :: Response < hyper :: Body > , io :: Error > { // This future must return a hyper::Response, but the response body might // borrow from the request. Instead, write the body in another future that // sends the response metadata (and a body channel) prior. let ( tx , rx ) = oneshot :: channel ( ) ; tokio :: spawn ( async move { // Get all of the information from Hyper. let ( h_parts , h_body ) = hyp_req . into_parts ( ) ; // Convert the Hyper request into a Rocket request. let req_res = Request :: from_hyp ( & rocket , h_parts . method , h_parts . headers , & h_parts . uri , h_addr ) ; let mut req = match req_res { Ok ( req ) => req , Err ( e ) => { error ! ( " " e ) ; // TODO: We don't have a request to pass in, so we just // fabricate one. This is weird. We should let the user know // that we failed to parse a request (by invoking some special // handler) instead of doing this. let dummy = Request :: new ( & rocket , Method :: Get , Origin :: dummy ( ) ) ; let r = rocket . handle_error ( Status :: BadRequest , & dummy ) . await ; return rocket . send_response ( r , tx ) . await ; } } ; // Retrieve the data from the hyper body. let mut data = Data :: from ( h_body ) ; // Dispatch the request to get a response, then write that response out. let token = rocket . preprocess_request ( & mut req , & mut data ) . await ; let r = rocket . dispatch ( token , & mut req , data ) . await ; rocket . send_response ( r , tx ) . await ; } ) ; // Receive the response written to `tx` by the task above. rx . await . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: Other , e ) ) }
This function tries to hide all of the Hyper-ness from Rocket.
This function tries to hide all of the Hyper - ness from Rocket .
rocket
Arc<Rocket<Orbit>>
h_addr
std::net::SocketAddr
hyp_req
hyper::Request<hyper::Body>
rocket
Arc<Rocket<Orbit>>
h_addr
std::net::SocketAddr
hyp_req
hyper::Request<hyper::Body>