diff --git a/src/response.rs b/src/response.rs index 4c27052..de209d0 100644 --- a/src/response.rs +++ b/src/response.rs @@ -498,13 +498,15 @@ impl Response { let compression = get_header(&headers, "content-encoding").and_then(Compression::from_header_value); + // remove Content-Encoding and length due to automatic decompression if compression.is_some() { - headers.retain(|h| h.name() != "content-encoding" && h.name() != "content-length"); - // remove Content-Encoding and length due to automatic decompression + headers.retain(|h| !h.is_name("content-encoding") && !h.is_name("content-length")); } + let url = unit.as_ref().map(|u| u.url.clone()); + Ok(Response { - url: None, + url, status_line, index, status, @@ -517,13 +519,6 @@ impl Response { }) } - pub(crate) fn do_from_request(unit: Unit, stream: Stream) -> Result { - let url = Some(unit.url.clone()); - let mut resp = Response::do_from_stream(stream, Some(unit))?; - resp.url = url; - Ok(resp) - } - #[cfg(test)] pub fn as_write_vec(&self) -> &[u8] { self.stream.as_write_vec() diff --git a/src/unit.rs b/src/unit.rs index fbeb172..b90fbc2 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -281,7 +281,10 @@ fn connect_inner( body::send_body(body, unit.is_chunked, &mut stream)?; // start reading the response to process cookies and redirects. - let result = Response::do_from_request(unit.clone(), stream); + // TODO: this unit.clone() bothers me. At this stage, we're not + // going to use the unit (much) anymore, and it should be possible + // to have ownership of it and pass it into the Response. + let result = Response::do_from_stream(stream, Some(unit.clone())); // https://tools.ietf.org/html/rfc7230#section-6.3.1 // When an inbound connection is closed prematurely, a client MAY