pub(crate) fn from_hyp(
        rocket: &'r Rocket<Orbit>,
        h_method: hyper::Method,
        h_headers: hyper::HeaderMap<hyper::HeaderValue>,
        h_uri: &'r hyper::Uri,
        h_addr: SocketAddr,
    ) -> Result<Request<'r>, Error<'r>> {
        // Get a copy of the URI (only supports path-and-query) for later use.
        let uri = match (h_uri.scheme(), h_uri.authority(), h_uri.path_and_query()) {
            (None, None, Some(path_query)) => path_query.as_str(),
            _ => return Err(Error::InvalidUri(h_uri)),
        };

        // Ensure that the method is known. TODO: Allow made-up methods?
        let method = match Method::from_hyp(&h_method) {
            Some(method) => method,
            None => return Err(Error::BadMethod(h_method))
        };

        // We need to re-parse the URI since we don't trust Hyper... :(
        let uri = Origin::parse(uri)?;

        // Construct the request object.
        let mut request = Request::new(rocket, method, uri);
        request.set_remote(h_addr);

        // Set the request cookies, if they exist.
        for header in h_headers.get_all("Cookie") {
            let raw_str = match std::str::from_utf8(header.as_bytes()) {
                Ok(string) => string,
                Err(_) => continue
            };

            for cookie_str in raw_str.split(';').map(|s| s.trim()) {
                if let Ok(cookie) = Cookie::parse_encoded(cookie_str) {
                    request.state.cookies.add_original(cookie.into_owned());
                }
            }
        }

        // Set the rest of the headers.
        // This is rather unfortunate and slow.
        for (name, value) in h_headers.iter() {
            // FIXME: This is not totally correct since values needn't be UTF8.
            let value_str = String::from_utf8_lossy(value.as_bytes()).into_owned();
            let header = Header::new(name.to_string(), value_str);
            request.add_header(header);
        }

        Ok(request)
    }
/// Convert from Hyper types into a Rocket Request.
Convert from Hyper types into a Rocket Request.
Convert from Hyper types into a Rocket Request .
pub(crate) fn from_hyp(
        rocket: &'r Rocket<Orbit>,
        h_method: hyper::Method,
        h_headers: hyper::HeaderMap<hyper::HeaderValue>,
        h_uri: &'r hyper::Uri,
        h_addr: SocketAddr,
    ) -> Result<Request<'r>, Error<'r>> {
        // Get a copy of the URI (only supports path-and-query) for later use.
        let uri = match (h_uri.scheme(), h_uri.authority(), h_uri.path_and_query()) {
            (None, None, Some(path_query)) => path_query.as_str(),
            _ => return Err(Error::InvalidUri(h_uri)),
        };
        // Ensure that the method is known. TODO: Allow made-up methods?
        let method = match Method::from_hyp(&h_method) {
            Some(method) => method,
            None => return Err(Error::BadMethod(h_method))
        };
        // We need to re-parse the URI since we don't trust Hyper... :(
        let uri = Origin::parse(uri)?;
        // Construct the request object.
        let mut request = Request::new(rocket, method, uri);
        request.set_remote(h_addr);
        // Set the request cookies, if they exist.
        for header in h_headers.get_all("Cookie") {
            let raw_str = match std::str::from_utf8(header.as_bytes()) {
                Ok(string) => string,
                Err(_) => continue
            };
            for cookie_str in raw_str.split(';').map(|s| s.trim()) {
                if let Ok(cookie) = Cookie::parse_encoded(cookie_str) {
                    request.state.cookies.add_original(cookie.into_owned());
                }
            }
        }
        // Set the rest of the headers.
        // This is rather unfortunate and slow.
        for (name, value) in h_headers.iter() {
            // FIXME: This is not totally correct since values needn't be UTF8.
            let value_str = String::from_utf8_lossy(value.as_bytes()).into_owned();
            let header = Header::new(name.to_string(), value_str);
            request.add_header(header);
        }
        Ok(request)
    }
pub ( crate ) fn from_hyp ( rocket : & ' r Rocket < Orbit > , h_method : hyper :: Method , h_headers : hyper :: HeaderMap < hyper :: HeaderValue > , h_uri : & ' r hyper :: Uri , h_addr : SocketAddr , ) -> Result < Request < ' r > , Error < ' r > > { // Get a copy of the URI (only supports path-and-query) for later use. let uri = match ( h_uri . scheme ( ) , h_uri . authority ( ) , h_uri . path_and_query ( ) ) { ( None , None , Some ( path_query ) ) => path_query . as_str ( ) , _ => return Err ( Error :: InvalidUri ( h_uri ) ) , } ; // Ensure that the method is known. TODO: Allow made-up methods? let method = match Method :: from_hyp ( & h_method ) { Some ( method ) => method , None => return Err ( Error :: BadMethod ( h_method ) ) } ; // We need to re-parse the URI since we don't trust Hyper... :( let uri = Origin :: parse ( uri ) ? ; // Construct the request object. let mut request = Request :: new ( rocket , method , uri ) ; request . set_remote ( h_addr ) ; // Set the request cookies, if they exist. for header in h_headers . get_all ( " " ) { let raw_str = match std :: str :: from_utf8 ( header . as_bytes ( ) ) { Ok ( string ) => string , Err ( _ ) => continue } ; for cookie_str in raw_str . split ( ';' ) . map ( | s | s . trim ( ) ) { if let Ok ( cookie ) = Cookie :: parse_encoded ( cookie_str ) { request . state . cookies . add_original ( cookie . into_owned ( ) ) ; } } } // Set the rest of the headers. // This is rather unfortunate and slow. for ( name , value ) in h_headers . iter ( ) { // FIXME: This is not totally correct since values needn't be UTF8. let value_str = String :: from_utf8_lossy ( value . as_bytes ( ) ) . into_owned ( ) ; let header = Header :: new ( name . to_string ( ) , value_str ) ; request . add_header ( header ) ; } Ok ( request ) }
Convert from Hyper types into a Rocket Request.
Convert from Hyper types into a Rocket Request .
rocket
&'r Rocket<Orbit>
h_method
hyper::Method
h_headers
hyper::HeaderMap<hyper::HeaderValue>
h_uri
&'r hyper::Uri
h_addr
SocketAddr
rocket
&'r Rocket<Orbit>
h_method
hyper::Method
h_headers
hyper::HeaderMap<hyper::HeaderValue>
h_uri
&'r hyper::Uri
h_addr
SocketAddr