mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 09:42:40 +01:00
fix end-of-stream handling in parse_payload
parse_payload can be called with a pre-filled buf. In this case, it's totaly fine for read_from_io to return sync::Ready(0) while buf is not empty. This is not an PayloadError::Incomplete. So, move the check for PayloadError::Incomplete down to the decoding code: If the decoder is not ready, but the input stream is finished, PayloadError::Incomplete will be returned.
This commit is contained in:
parent
d39b531537
commit
72bc1546c4
@ -81,16 +81,11 @@ impl HttpResponseParser {
|
|||||||
if self.decoder.is_some() {
|
if self.decoder.is_some() {
|
||||||
loop {
|
loop {
|
||||||
// read payload
|
// read payload
|
||||||
let not_ready = match utils::read_from_io(io, buf) {
|
let (not_ready, stream_finished) = match utils::read_from_io(io, buf) {
|
||||||
Ok(Async::Ready(0)) => {
|
Ok(Async::Ready(0)) => (false, true),
|
||||||
if buf.is_empty() {
|
|
||||||
return Err(PayloadError::Incomplete)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
Ok(Async::NotReady) => true,
|
Ok(Async::NotReady) => (true, false),
|
||||||
_ => false,
|
_ => (false, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
match self.decoder.as_mut().unwrap().decode(buf) {
|
match self.decoder.as_mut().unwrap().decode(buf) {
|
||||||
@ -104,6 +99,9 @@ impl HttpResponseParser {
|
|||||||
if not_ready {
|
if not_ready {
|
||||||
return Ok(Async::NotReady)
|
return Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
|
if stream_finished {
|
||||||
|
return Err(PayloadError::Incomplete)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user