fix(client): improve keep-alive of bodyless Responses

This commit is contained in:
Sean McArthur
2015-08-05 16:45:54 -07:00
parent 31f117ea08
commit 67c284a96a
4 changed files with 15 additions and 2 deletions

View File

@@ -47,9 +47,9 @@ impl Response {
version: version, version: version,
headers: headers, headers: headers,
url: url, url: url,
message: message,
status_raw: raw_status, status_raw: raw_status,
is_drained: false, is_drained: !message.has_body(),
message: message,
}) })
} }

View File

@@ -203,6 +203,13 @@ impl HttpMessage for Http11Message {
}) })
} }
fn has_body(&self) -> bool {
match self.reader {
Some(EmptyReader(..)) => false,
_ => true
}
}
#[cfg(feature = "timeouts")] #[cfg(feature = "timeouts")]
#[inline] #[inline]
fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> { fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {

View File

@@ -400,6 +400,10 @@ impl<S> HttpMessage for Http2Message<S> where S: CloneableStream {
Ok(head) Ok(head)
} }
fn has_body(&self) -> bool {
true
}
#[cfg(feature = "timeouts")] #[cfg(feature = "timeouts")]
#[inline] #[inline]
fn set_read_timeout(&self, _dur: Option<Duration>) -> io::Result<()> { fn set_read_timeout(&self, _dur: Option<Duration>) -> io::Result<()> {

View File

@@ -72,6 +72,8 @@ pub trait HttpMessage: Write + Read + Send + Any + Typeable + Debug {
fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>; fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>;
/// Closes the underlying HTTP connection. /// Closes the underlying HTTP connection.
fn close_connection(&mut self) -> ::Result<()>; fn close_connection(&mut self) -> ::Result<()>;
/// Returns whether the incoming message has a body.
fn has_body(&self) -> bool;
} }
impl HttpMessage { impl HttpMessage {