pub fn new(stream: Box<NetworkStream + Send>) -> HttpResult<Response> {
        let mut stream = BufferedReader::new(stream);
        let (version, raw_status) = try!(read_status_line(&mut stream));
        let status = match FromPrimitive::from_u16(raw_status.0) {
            Some(status) => status,
            None => return Err(HttpStatusError)
        };
        debug!("{} {}", version, status);

        let headers = try!(header::Headers::from_raw(&mut stream));
        debug!("Headers: [\n{}]", headers);

        let body = if headers.has::<TransferEncoding>() {
            match headers.get::<TransferEncoding>() {
                Some(&TransferEncoding(ref codings)) => {
                    if codings.len() > 1 {
                        debug!("TODO: #2 handle other codings: {}", codings);
                    };

                    if codings.contains(&Chunked) {
                        ChunkedReader(stream, None)
                    } else {
                        debug!("not chuncked. read till eof");
                        EofReader(stream)
                    }
                }
                None => unreachable!()
            }
        } else if headers.has::<ContentLength>() {
            match headers.get::<ContentLength>() {
                Some(&ContentLength(len)) => SizedReader(stream, len),
                None => unreachable!()
            }
        } else {
            debug!("neither Transfer-Encoding nor Content-Length");
            EofReader(stream)
        };

        Ok(Response {
            status: status,
            version: version,
            headers: headers,
            body: body,
            status_raw: raw_status,
        })
    }
/// Creates a new response from a server.
Creates a new response from a server.
Creates a new response from a server .
pub fn new(stream: Box<NetworkStream + Send>) -> HttpResult<Response> {
        let mut stream = BufferedReader::new(stream);
        let (version, raw_status) = try!(read_status_line(&mut stream));
        let status = match FromPrimitive::from_u16(raw_status.0) {
            Some(status) => status,
            None => return Err(HttpStatusError)
        };
        debug!("{} {}", version, status);
        let headers = try!(header::Headers::from_raw(&mut stream));
        debug!("Headers: [\n{}]", headers);
        let body = if headers.has::<TransferEncoding>() {
            match headers.get::<TransferEncoding>() {
                Some(&TransferEncoding(ref codings)) => {
                    if codings.len() > 1 {
                        debug!("TODO: #2 handle other codings: {}", codings);
                    };
                    if codings.contains(&Chunked) {
                        ChunkedReader(stream, None)
                    } else {
                        debug!("not chuncked. read till eof");
                        EofReader(stream)
                    }
                }
                None => unreachable!()
            }
        } else if headers.has::<ContentLength>() {
            match headers.get::<ContentLength>() {
                Some(&ContentLength(len)) => SizedReader(stream, len),
                None => unreachable!()
            }
        } else {
            debug!("neither Transfer-Encoding nor Content-Length");
            EofReader(stream)
        };
        Ok(Response {
            status: status,
            version: version,
            headers: headers,
            body: body,
            status_raw: raw_status,
        })
    }
pub fn new ( stream : Box < NetworkStream + Send > ) -> HttpResult < Response > { let mut stream = BufferedReader :: new ( stream ) ; let ( version , raw_status ) = try ! ( read_status_line ( mut stream ) ) ; let status = match FromPrimitive :: from_u16 ( raw_status . 0 ) { Some ( status ) => status , None => return Err ( HttpStatusError ) } ; debug ! ( " " version status ) ; let headers = try ! ( header Headers from_raw ( mut stream ) ) ; debug ! ( " \n " headers ) ; let body = if headers . has :: < TransferEncoding > ( ) { match headers . get :: < TransferEncoding > ( ) { Some ( & TransferEncoding ( ref codings ) ) => { if codings . len ( ) > 1 { debug ! ( " " codings ) ; } ; if codings . contains ( & Chunked ) { ChunkedReader ( stream , None ) } else { debug ! ( " " ) ; EofReader ( stream ) } } None => unreachable ! ( ) } } else if headers . has :: < ContentLength > ( ) { match headers . get :: < ContentLength > ( ) { Some ( & ContentLength ( len ) ) => SizedReader ( stream , len ) , None => unreachable ! ( ) } } else { debug ! ( " " ) ; EofReader ( stream ) } ; Ok ( Response { status : status , version : version , headers : headers , body : body , status_raw : raw_status , } ) }
Creates a new response from a server.
Creates a new response from a server .
stream
Box<NetworkStream + Send>
stream
Box<NetworkStream + Send>