Return stream to pool on exact read (#509)
If the user reads exactly the number of bytes in the response, then drops the Read object, streams will never get returned to the pool since the user never triggered a read past the end of the LimitedRead. This fixes that by making PoolReturnRead aware of the level below it, so it can ask if a stream is "done" without actually doing a read. Also, a refactorign: Previously, Response contained an Option<Box<Unit>> because the testing method `from_str()` would construct a Response with no associated Unit. However, this increased code complexity with no corresponding test benefit. Instead, construct a fake Unit in from_str(). Also, instead of taking an `Option<Box<Unit>>`, PoolReturnRead now takes a URL (to figure out host and port for the PoolKey) and an &Agent where it will return the stream. This cuts interconnectedness somewhat: PoolReturnRead doesn't need to know about Unit anymore.
This commit is contained in:
committed by
GitHub
parent
4d77d365a0
commit
101467f13f
@@ -284,7 +284,7 @@ fn connect_inner(
|
||||
// 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()));
|
||||
let result = Response::do_from_stream(stream, unit.clone());
|
||||
|
||||
// https://tools.ietf.org/html/rfc7230#section-6.3.1
|
||||
// When an inbound connection is closed prematurely, a client MAY
|
||||
|
||||
Reference in New Issue
Block a user