pub fn from_http(req: HttpRequest<'a, 'b>, local_addr: SocketAddr, protocol: &Protocol)
                     -> Result<Request<'a, 'b>, String> {
        let (addr, method, headers, uri, _, reader) = req.deconstruct();

        let url = match uri {
            AbsoluteUri(ref url) => {
                match Url::from_generic_url(url.clone()) {
                    Ok(url) => url,
                    Err(e) => return Err(e)
                }
            },

            AbsolutePath(ref path) => {
                // Attempt to prepend the Host header (mandatory in HTTP/1.1)
                let url_string = match headers.get::<headers::Host>() {
                    Some(ref host) => {
                        format!("{}://{}:{}{}", protocol.name(), host.hostname, local_addr.port(),
                                path)
                    },
                    None => return Err("No host specified in request".into())
                };

                match Url::parse(&url_string) {
                    Ok(url) => url,
                    Err(e) => return Err(format!("Couldn't parse requested URL: {}", e))
                }
            },
            _ => return Err("Unsupported request URI".into())
        };

        Ok(Request {
            url: url,
            remote_addr: addr,
            local_addr: local_addr,
            headers: headers,
            body: Body::new(reader),
            method: method,
            extensions: TypeMap::new()
        })
    }
/// Create a request from an HttpRequest.
///
/// This constructor consumes the HttpRequest.
Create a request from an HttpRequest.
This constructor consumes the HttpRequest.
Create a request from an HttpRequest . This constructor consumes the HttpRequest .
pub fn from_http(req: HttpRequest<'a, 'b>, local_addr: SocketAddr, protocol: &Protocol)
                     -> Result<Request<'a, 'b>, String> {
        let (addr, method, headers, uri, _, reader) = req.deconstruct();
        let url = match uri {
            AbsoluteUri(ref url) => {
                match Url::from_generic_url(url.clone()) {
                    Ok(url) => url,
                    Err(e) => return Err(e)
                }
            },
            AbsolutePath(ref path) => {
                // Attempt to prepend the Host header (mandatory in HTTP/1.1)
                let url_string = match headers.get::<headers::Host>() {
                    Some(ref host) => {
                        format!("{}://{}:{}{}", protocol.name(), host.hostname, local_addr.port(),
                                path)
                    },
                    None => return Err("No host specified in request".into())
                };
                match Url::parse(&url_string) {
                    Ok(url) => url,
                    Err(e) => return Err(format!("Couldn't parse requested URL: {}", e))
                }
            },
            _ => return Err("Unsupported request URI".into())
        };
        Ok(Request {
            url: url,
            remote_addr: addr,
            local_addr: local_addr,
            headers: headers,
            body: Body::new(reader),
            method: method,
            extensions: TypeMap::new()
        })
    }
pub fn from_http ( req : HttpRequest < ' a , ' b > , local_addr : SocketAddr , protocol : & Protocol ) -> Result < Request < ' a , ' b > , String > { let ( addr , method , headers , uri , _ , reader ) = req . deconstruct ( ) ; let url = match uri { AbsoluteUri ( ref url ) => { match Url :: from_generic_url ( url . clone ( ) ) { Ok ( url ) => url , Err ( e ) => return Err ( e ) } } , AbsolutePath ( ref path ) => { // Attempt to prepend the Host header (mandatory in HTTP/1.1) let url_string = match headers . get :: < headers :: Host > ( ) { Some ( ref host ) => { format ! ( " " protocol name ( ) host hostname local_addr port ( ) path ) } , None => return Err ( " " . into ( ) ) } ; match Url :: parse ( & url_string ) { Ok ( url ) => url , Err ( e ) => return Err ( format ! ( " " e ) ) } } , _ => return Err ( " " . into ( ) ) } ; Ok ( Request { url : url , remote_addr : addr , local_addr : local_addr , headers : headers , body : Body :: new ( reader ) , method : method , extensions : TypeMap :: new ( ) } ) }
Create a request from an HttpRequest.
Create a request from an HttpRequest .
req
HttpRequest<'a, 'b>
local_addr
SocketAddr
protocol
&Protocol