Skip to content

Commit a5e6174

Browse files
committed
fix(client): don't close stream until EOF
Closes #543
1 parent e64ce8c commit a5e6174

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/client/response.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ impl Response {
4343
debug!("version={:?}, status={:?}", head.version, status);
4444
debug!("headers={:?}", headers);
4545

46-
if !http::should_keep_alive(head.version, &headers) {
47-
try!(stream.get_mut().close(Shutdown::Write));
48-
}
4946

5047
let body = if headers.has::<TransferEncoding>() {
5148
match headers.get::<TransferEncoding>() {
@@ -97,7 +94,15 @@ impl Response {
9794
impl Read for Response {
9895
#[inline]
9996
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
100-
self.body.read(buf)
97+
let count = try!(self.body.read(buf));
98+
99+
if count == 0 {
100+
if !http::should_keep_alive(self.version, &self.headers) {
101+
try!(self.body.get_mut().get_mut().close(Shutdown::Both));
102+
}
103+
}
104+
105+
Ok(count)
101106
}
102107
}
103108

0 commit comments

Comments
 (0)