From a5e6174efd57afb1df7113c64f4e7718a3a94187 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 23 May 2015 15:11:44 -0700 Subject: [PATCH] fix(client): don't close stream until EOF Closes #543 --- src/client/response.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/response.rs b/src/client/response.rs index c8c4a71c28..f21f762328 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -43,9 +43,6 @@ impl Response { debug!("version={:?}, status={:?}", head.version, status); debug!("headers={:?}", headers); - if !http::should_keep_alive(head.version, &headers) { - try!(stream.get_mut().close(Shutdown::Write)); - } let body = if headers.has::() { match headers.get::() { @@ -97,7 +94,15 @@ impl Response { impl Read for Response { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.body.read(buf) + let count = try!(self.body.read(buf)); + + if count == 0 { + if !http::should_keep_alive(self.version, &self.headers) { + try!(self.body.get_mut().get_mut().close(Shutdown::Both)); + } + } + + Ok(count) } }