Tidy up Response::url initialization

This commit is contained in:
Martin Algesten
2021-12-20 10:20:44 +01:00
parent 87cf59d399
commit 7b2f28bbc2
2 changed files with 9 additions and 11 deletions

View File

@@ -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<Response, Error> {
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()