pub fn new(stream: Box<NetworkStream + Send>) -> HttpResult<Response> {
        let mut stream = BufferedReader::new(stream);
        let (version, status) = try!(read_status_line(&mut stream));
        let headers = try!(header::Headers::from_raw(&mut stream));

        debug!("{} {}", version, status);
        debug!("{}", 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,
        })
    }
/// 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, status) = try!(read_status_line(&mut stream));
        let headers = try!(header::Headers::from_raw(&mut stream));
        debug!("{} {}", version, status);
        debug!("{}", 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,
        })
    }
pub fn new ( stream : Box < NetworkStream + Send > ) -> HttpResult < Response > { let mut stream = BufferedReader :: new ( stream ) ; let ( version , status ) = try ! ( read_status_line ( mut stream ) ) ; let headers = try ! ( header Headers from_raw ( mut stream ) ) ; debug ! ( " " version status ) ; debug ! ( " " 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 , } ) }
Creates a new response from a server.
Creates a new response from a server .
stream
Box<NetworkStream + Send>
stream
Box<NetworkStream + Send>