async fn hyper_service_fn(
    rocket: Arc<Rocket<Orbit>>,
    conn: ConnectionMeta,
    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 {
        // Convert a Hyper request into a Rocket request.
        let (h_parts, mut h_body) = hyp_req.into_parts();
        match Request::from_hyp(&rocket, &h_parts, Some(conn)) {
            Ok(mut req) => {
                // Convert into Rocket `Data`, dispatch request, write response.
                let mut data = Data::from(&mut h_body);
                let token = rocket.preprocess_request(&mut req, &mut data).await;
                let response = rocket.dispatch(token, &mut req, data).await;
                rocket.send_response(response, tx).await;
            },
            Err(e) => {
                warn!("Bad incoming HTTP request.");
                e.errors.iter().for_each(|e| warn_!("Error: {}.", e));
                warn_!("Dispatching salvaged request to catcher: {}.", e.request);

                let response = rocket.handle_error(Status::BadRequest, &e.request).await;
                rocket.send_response(response, tx).await;
            }
        }
    });

    // Receive the response written to `tx` by the task above.
    rx.await.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, 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>>,
    conn: ConnectionMeta,
    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 {
        // Convert a Hyper request into a Rocket request.
        let (h_parts, mut h_body) = hyp_req.into_parts();
        match Request::from_hyp(&rocket, &h_parts, Some(conn)) {
            Ok(mut req) => {
                // Convert into Rocket `Data`, dispatch request, write response.
                let mut data = Data::from(&mut h_body);
                let token = rocket.preprocess_request(&mut req, &mut data).await;
                let response = rocket.dispatch(token, &mut req, data).await;
                rocket.send_response(response, tx).await;
            },
            Err(e) => {
                warn!("Bad incoming HTTP request.");
                e.errors.iter().for_each(|e| warn_!("Error: {}.", e));
                warn_!("Dispatching salvaged request to catcher: {}.", e.request);
                let response = rocket.handle_error(Status::BadRequest, &e.request).await;
                rocket.send_response(response, tx).await;
            }
        }
    });
    // Receive the response written to `tx` by the task above.
    rx.await.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e))
}
async fn hyper_service_fn ( rocket : Arc < Rocket < Orbit > > , conn : ConnectionMeta , 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 { // Convert a Hyper request into a Rocket request. let ( h_parts , mut h_body ) = hyp_req . into_parts ( ) ; match Request :: from_hyp ( & rocket , & h_parts , Some ( conn ) ) { Ok ( mut req ) => { // Convert into Rocket `Data`, dispatch request, write response. let mut data = Data :: from ( & mut h_body ) ; let token = rocket . preprocess_request ( & mut req , & mut data ) . await ; let response = rocket . dispatch ( token , & mut req , data ) . await ; rocket . send_response ( response , tx ) . await ; } , Err ( e ) => { warn ! ( " " ) ; e . errors . iter ( ) . for_each ( | e | warn_ ! ( " " e ) ) ; warn_ ! ( " " e request ) ; let response = rocket . handle_error ( Status :: BadRequest , & e . request ) . await ; rocket . send_response ( response , tx ) . await ; } } } ) ; // Receive the response written to `tx` by the task above. rx . await . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: BrokenPipe , 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>>
conn
ConnectionMeta
hyp_req
hyper::Request<hyper::Body>
rocket
Arc<Rocket<Orbit>>
conn
ConnectionMeta
hyp_req
hyper::Request<hyper::Body>