Merge pull request #545 from hyperium/issue-543
fix(client): don't close stream until EOF
This commit is contained in:
		| @@ -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::<TransferEncoding>() { | ||||
|             match headers.get::<TransferEncoding>() { | ||||
| @@ -97,7 +94,15 @@ impl Response { | ||||
| impl Read for Response { | ||||
|     #[inline] | ||||
|     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) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/http.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/http.rs
									
									
									
									
									
								
							| @@ -59,6 +59,16 @@ impl<R: Read> HttpReader<R> { | ||||
|             EmptyReader(r) => r, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// Gets a mutable reference to the underlying Reader. | ||||
|     pub fn get_mut(&mut self) -> &mut R { | ||||
|         match *self { | ||||
|             SizedReader(ref mut r, _) => r, | ||||
|             ChunkedReader(ref mut r, _) => r, | ||||
|             EofReader(ref mut r) => r, | ||||
|             EmptyReader(ref mut r) => r, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<R> fmt::Debug for HttpReader<R> { | ||||
| @@ -121,7 +131,9 @@ impl<R: Read> Read for HttpReader<R> { | ||||
|                 Ok(count as usize) | ||||
|             }, | ||||
|             EofReader(ref mut body) => { | ||||
|                 body.read(buf) | ||||
|                 let r = body.read(buf); | ||||
|                 trace!("eofread: {:?}", r); | ||||
|                 r | ||||
|             }, | ||||
|             EmptyReader(_) => Ok(0) | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user