Skip to content

Commit 0955dfe

Browse files
response: Don't take ownership of unit in do_from_stream
There does not seem to be any good reason to take ownership of it. Makes us able to remove a clone and a TODO comment.
1 parent 489b305 commit 0955dfe

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/response.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl Response {
561561
/// let resp = ureq::Response::do_from_read(read);
562562
///
563563
/// assert_eq!(resp.status(), 401);
564-
pub(crate) fn do_from_stream(stream: Stream, unit: Unit) -> Result<Response, Error> {
564+
pub(crate) fn do_from_stream(stream: Stream, unit: &Unit) -> Result<Response, Error> {
565565
let remote_addr = stream.remote_addr;
566566

567567
let local_addr = match stream.socket() {
@@ -609,7 +609,7 @@ impl Response {
609609
}
610610

611611
let reader =
612-
Self::stream_to_reader(stream, &unit, body_type, compression, connection_option);
612+
Self::stream_to_reader(stream, unit, body_type, compression, connection_option);
613613

614614
let url = unit.url.clone();
615615

@@ -766,7 +766,7 @@ impl FromStr for Response {
766766
&request_reader,
767767
None,
768768
);
769-
Self::do_from_stream(stream, unit)
769+
Self::do_from_stream(stream, &unit)
770770
}
771771
}
772772

@@ -1150,7 +1150,7 @@ mod tests {
11501150
&request_reader,
11511151
None,
11521152
);
1153-
let resp = Response::do_from_stream(s.into(), unit).unwrap();
1153+
let resp = Response::do_from_stream(s.into(), &unit).unwrap();
11541154
assert_eq!(resp.status(), 200);
11551155
assert_eq!(resp.header("x-geo-header"), None);
11561156
}
@@ -1206,7 +1206,7 @@ mod tests {
12061206
);
12071207
Response::do_from_stream(
12081208
stream,
1209-
Unit::new(
1209+
&Unit::new(
12101210
&agent,
12111211
"GET",
12121212
&"https://example.com/".parse().unwrap(),
@@ -1238,7 +1238,7 @@ mod tests {
12381238
);
12391239
let resp = Response::do_from_stream(
12401240
stream,
1241-
Unit::new(
1241+
&Unit::new(
12421242
&agent,
12431243
"GET",
12441244
&"https://example.com/".parse().unwrap(),

src/stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub(crate) fn connect_host(
456456
let pool_key = PoolKey::from_parts(unit.url.scheme(), hostname, port);
457457
let pool_returner = PoolReturner::new(&unit.agent, pool_key);
458458
let s = Stream::new(s, remote_addr, pool_returner);
459-
let response = Response::do_from_stream(s, unit.clone())?;
459+
let response = Response::do_from_stream(s, unit)?;
460460
Proxy::verify_response(&response)?;
461461
}
462462
}

src/unit.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ fn connect_inner(
281281
body::send_body(body, unit.is_chunked, &mut stream)?;
282282

283283
// start reading the response to process cookies and redirects.
284-
// TODO: this unit.clone() bothers me. At this stage, we're not
285-
// going to use the unit (much) anymore, and it should be possible
286-
// to have ownership of it and pass it into the Response.
287-
let result = Response::do_from_stream(stream, unit.clone());
284+
let result = Response::do_from_stream(stream, unit);
288285

289286
// https://tools.ietf.org/html/rfc7230#section-6.3.1
290287
// When an inbound connection is closed prematurely, a client MAY

0 commit comments

Comments
 (0)