Tidy up Response::url initialization
This commit is contained in:
@@ -498,13 +498,15 @@ impl Response {
|
|||||||
let compression =
|
let compression =
|
||||||
get_header(&headers, "content-encoding").and_then(Compression::from_header_value);
|
get_header(&headers, "content-encoding").and_then(Compression::from_header_value);
|
||||||
|
|
||||||
|
// remove Content-Encoding and length due to automatic decompression
|
||||||
if compression.is_some() {
|
if compression.is_some() {
|
||||||
headers.retain(|h| h.name() != "content-encoding" && h.name() != "content-length");
|
headers.retain(|h| !h.is_name("content-encoding") && !h.is_name("content-length"));
|
||||||
// remove Content-Encoding and length due to automatic decompression
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let url = unit.as_ref().map(|u| u.url.clone());
|
||||||
|
|
||||||
Ok(Response {
|
Ok(Response {
|
||||||
url: None,
|
url,
|
||||||
status_line,
|
status_line,
|
||||||
index,
|
index,
|
||||||
status,
|
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)]
|
#[cfg(test)]
|
||||||
pub fn as_write_vec(&self) -> &[u8] {
|
pub fn as_write_vec(&self) -> &[u8] {
|
||||||
self.stream.as_write_vec()
|
self.stream.as_write_vec()
|
||||||
|
|||||||
@@ -281,7 +281,10 @@ fn connect_inner(
|
|||||||
body::send_body(body, unit.is_chunked, &mut stream)?;
|
body::send_body(body, unit.is_chunked, &mut stream)?;
|
||||||
|
|
||||||
// start reading the response to process cookies and redirects.
|
// 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
|
// https://tools.ietf.org/html/rfc7230#section-6.3.1
|
||||||
// When an inbound connection is closed prematurely, a client MAY
|
// When an inbound connection is closed prematurely, a client MAY
|
||||||
|
|||||||
Reference in New Issue
Block a user