From 67c284a96a006f888f43d8af929516465de76dea Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 5 Aug 2015 16:45:54 -0700 Subject: [PATCH] fix(client): improve keep-alive of bodyless Responses --- src/client/response.rs | 4 ++-- src/http/h1.rs | 7 +++++++ src/http/h2.rs | 4 ++++ src/http/message.rs | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/response.rs b/src/client/response.rs index 44684edaba..46882d42b0 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -47,9 +47,9 @@ impl Response { version: version, headers: headers, url: url, - message: message, status_raw: raw_status, - is_drained: false, + is_drained: !message.has_body(), + message: message, }) } diff --git a/src/http/h1.rs b/src/http/h1.rs index 71d3a23271..44cd35dbfa 100644 --- a/src/http/h1.rs +++ b/src/http/h1.rs @@ -203,6 +203,13 @@ impl HttpMessage for Http11Message { }) } + fn has_body(&self) -> bool { + match self.reader { + Some(EmptyReader(..)) => false, + _ => true + } + } + #[cfg(feature = "timeouts")] #[inline] fn set_read_timeout(&self, dur: Option) -> io::Result<()> { diff --git a/src/http/h2.rs b/src/http/h2.rs index 84af8ff573..136bf80c9c 100644 --- a/src/http/h2.rs +++ b/src/http/h2.rs @@ -400,6 +400,10 @@ impl HttpMessage for Http2Message where S: CloneableStream { Ok(head) } + fn has_body(&self) -> bool { + true + } + #[cfg(feature = "timeouts")] #[inline] fn set_read_timeout(&self, _dur: Option) -> io::Result<()> { diff --git a/src/http/message.rs b/src/http/message.rs index f0f2d9b21e..b969d3140b 100644 --- a/src/http/message.rs +++ b/src/http/message.rs @@ -72,6 +72,8 @@ pub trait HttpMessage: Write + Read + Send + Any + Typeable + Debug { fn set_write_timeout(&self, dur: Option) -> io::Result<()>; /// Closes the underlying HTTP connection. fn close_connection(&mut self) -> ::Result<()>; + /// Returns whether the incoming message has a body. + fn has_body(&self) -> bool; } impl HttpMessage {