mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
Simplify buffer reading logic. Remove duplicate code.
This commit is contained in:
parent
487519acec
commit
2341656173
@ -38,20 +38,17 @@ impl HttpResponseParser {
|
|||||||
where
|
where
|
||||||
T: IoStream,
|
T: IoStream,
|
||||||
{
|
{
|
||||||
// if buf is empty parse_message will always return NotReady, let's avoid that
|
loop {
|
||||||
if buf.is_empty() {
|
|
||||||
match io.read_available(buf) {
|
match io.read_available(buf) {
|
||||||
Ok(Async::Ready((true, true))) => (),
|
|
||||||
Ok(Async::Ready((false, true))) => {
|
Ok(Async::Ready((false, true))) => {
|
||||||
return Err(HttpResponseParserError::Disconnect)
|
return Err(HttpResponseParserError::Disconnect)
|
||||||
}
|
}
|
||||||
Ok(Async::Ready((_, false))) => (),
|
Ok(Async::Ready(_)) => (),
|
||||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||||
Err(err) => return Err(HttpResponseParserError::Error(err.into())),
|
Err(err) => {
|
||||||
|
return Err(HttpResponseParserError::Error(err.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
|
||||||
match HttpResponseParser::parse_message(buf)
|
match HttpResponseParser::parse_message(buf)
|
||||||
.map_err(HttpResponseParserError::Error)?
|
.map_err(HttpResponseParserError::Error)?
|
||||||
{
|
{
|
||||||
@ -63,17 +60,6 @@ impl HttpResponseParser {
|
|||||||
if buf.capacity() >= MAX_BUFFER_SIZE {
|
if buf.capacity() >= MAX_BUFFER_SIZE {
|
||||||
return Err(HttpResponseParserError::Error(ParseError::TooLarge));
|
return Err(HttpResponseParserError::Error(ParseError::TooLarge));
|
||||||
}
|
}
|
||||||
match io.read_available(buf) {
|
|
||||||
Ok(Async::Ready((true, true))) => (),
|
|
||||||
Ok(Async::Ready((false, true))) => {
|
|
||||||
return Err(HttpResponseParserError::Disconnect)
|
|
||||||
}
|
|
||||||
Ok(Async::Ready((_, false))) => (),
|
|
||||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
|
||||||
Err(err) => {
|
|
||||||
return Err(HttpResponseParserError::Error(err.into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user