fix(client): don't close stream until EOF

Closes #543
This commit is contained in:
Sean McArthur
2015-05-23 15:11:44 -07:00
parent e64ce8c05e
commit a5e6174efd

View File

@@ -43,9 +43,6 @@ impl Response {
debug!("version={:?}, status={:?}", head.version, status); debug!("version={:?}, status={:?}", head.version, status);
debug!("headers={:?}", headers); debug!("headers={:?}", headers);
if !http::should_keep_alive(head.version, &headers) {
try!(stream.get_mut().close(Shutdown::Write));
}
let body = if headers.has::<TransferEncoding>() { let body = if headers.has::<TransferEncoding>() {
match headers.get::<TransferEncoding>() { match headers.get::<TransferEncoding>() {
@@ -97,7 +94,15 @@ impl Response {
impl Read for Response { impl Read for Response {
#[inline] #[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
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)
} }
} }