-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lib): properly handle body streaming errors
- Loading branch information
1 parent
7888451
commit 7a48d0e
Showing
4 changed files
with
143 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,18 +235,31 @@ where I: AsyncRead + AsyncWrite, | |
|
||
let (reading, ret) = match self.state.reading { | ||
Reading::Body(ref mut decoder) => { | ||
let slice = try_ready!(decoder.decode(&mut self.io)); | ||
if !slice.is_empty() { | ||
return Ok(Async::Ready(Some(super::Chunk::from(slice)))); | ||
} else if decoder.is_eof() { | ||
debug!("incoming body completed"); | ||
(Reading::KeepAlive, Ok(Async::Ready(None))) | ||
} else { | ||
trace!("decode stream unexpectedly ended"); | ||
//TODO: Should this return an UnexpectedEof? | ||
(Reading::Closed, Ok(Async::Ready(None))) | ||
match decoder.decode(&mut self.io) { | ||
Ok(Async::Ready(slice)) => { | ||
let chunk = if !slice.is_empty() { | ||
Some(super::Chunk::from(slice)) | ||
} else { | ||
None | ||
}; | ||
let reading = if decoder.is_eof() { | ||
debug!("incoming body completed"); | ||
Reading::KeepAlive | ||
} else if chunk.is_some() { | ||
Reading::Body(decoder.clone()) | ||
} else { | ||
trace!("decode stream unexpectedly ended"); | ||
//TODO: Should this return an UnexpectedEof? | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
seanmonstar
Author
Member
|
||
Reading::Closed | ||
}; | ||
(reading, Ok(Async::Ready(chunk))) | ||
}, | ||
Ok(Async::NotReady) => return Ok(Async::NotReady), | ||
Err(e) => { | ||
trace!("decode stream error: {}", e); | ||
(Reading::Closed, Err(e)) | ||
}, | ||
} | ||
|
||
}, | ||
_ => unreachable!("read_body invalid state: {:?}", self.state.reading), | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This would trigger if the server cuts off the response midway through? It should trigger an error then I think.