mirror of
https://github.com/actix/actix-web.git
synced 2025-01-22 23:18:07 +00:00
If buffer is empty, read more data before calling parser.
This commit is contained in:
parent
a42a8a2321
commit
66881d7dd1
1 changed files with 17 additions and 16 deletions
|
@ -39,6 +39,23 @@ impl HttpResponseParser {
|
|||
T: IoStream,
|
||||
{
|
||||
loop {
|
||||
// Don't call parser until we have data to parse.
|
||||
if !buf.is_empty() {
|
||||
match HttpResponseParser::parse_message(buf)
|
||||
.map_err(HttpResponseParserError::Error)?
|
||||
{
|
||||
Async::Ready((msg, decoder)) => {
|
||||
self.decoder = decoder;
|
||||
return Ok(Async::Ready(msg));
|
||||
}
|
||||
Async::NotReady => {
|
||||
if buf.capacity() >= MAX_BUFFER_SIZE {
|
||||
return Err(HttpResponseParserError::Error(ParseError::TooLarge));
|
||||
}
|
||||
// Parser needs more data.
|
||||
}
|
||||
}
|
||||
}
|
||||
// Read some more data into the buffer for the parser.
|
||||
match io.read_available(buf) {
|
||||
Ok(Async::Ready((false, true))) => {
|
||||
|
@ -50,22 +67,6 @@ impl HttpResponseParser {
|
|||
return Err(HttpResponseParserError::Error(err.into()))
|
||||
}
|
||||
}
|
||||
|
||||
// Call HTTP response parser.
|
||||
match HttpResponseParser::parse_message(buf)
|
||||
.map_err(HttpResponseParserError::Error)?
|
||||
{
|
||||
Async::Ready((msg, decoder)) => {
|
||||
self.decoder = decoder;
|
||||
return Ok(Async::Ready(msg));
|
||||
}
|
||||
Async::NotReady => {
|
||||
if buf.capacity() >= MAX_BUFFER_SIZE {
|
||||
return Err(HttpResponseParserError::Error(ParseError::TooLarge));
|
||||
}
|
||||
// Parser needs more data. Loop and read more data.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue