mirror of https://github.com/fafhrd91/actix-web
use decoder::max_buffer_size as early return point on read
This commit is contained in:
parent
09128d1763
commit
a3fd266629
|
@ -14,7 +14,7 @@ use crate::header::HeaderMap;
|
||||||
use crate::message::{ConnectionType, ResponseHead};
|
use crate::message::{ConnectionType, ResponseHead};
|
||||||
use crate::request::Request;
|
use crate::request::Request;
|
||||||
|
|
||||||
const MAX_BUFFER_SIZE: usize = 131_072;
|
pub(crate) const MAX_BUFFER_SIZE: usize = 131_072;
|
||||||
const MAX_HEADERS: usize = 96;
|
const MAX_HEADERS: usize = 96;
|
||||||
|
|
||||||
/// Incoming message decoder
|
/// Incoming message decoder
|
||||||
|
@ -204,7 +204,8 @@ impl MessageType for Request {
|
||||||
(len, method, uri, version, req.headers.len())
|
(len, method, uri, version, req.headers.len())
|
||||||
}
|
}
|
||||||
httparse::Status::Partial => {
|
httparse::Status::Partial => {
|
||||||
return if src.len() >= super::dispatcher::MAX_HW_BUFFER_SIZE {
|
return if src.len() >= MAX_BUFFER_SIZE {
|
||||||
|
trace!("MAX_BUFFER_SIZE unprocessed data reached, closing");
|
||||||
Err(ParseError::TooLarge)
|
Err(ParseError::TooLarge)
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -228,9 +229,6 @@ impl MessageType for Request {
|
||||||
PayloadLength::None => {
|
PayloadLength::None => {
|
||||||
if method == Method::CONNECT {
|
if method == Method::CONNECT {
|
||||||
PayloadType::Stream(PayloadDecoder::eof())
|
PayloadType::Stream(PayloadDecoder::eof())
|
||||||
} else if src.len() >= MAX_BUFFER_SIZE {
|
|
||||||
trace!("MAX_BUFFER_SIZE unprocessed data reached, closing");
|
|
||||||
return Err(ParseError::TooLarge);
|
|
||||||
} else {
|
} else {
|
||||||
PayloadType::None
|
PayloadType::None
|
||||||
}
|
}
|
||||||
|
@ -279,7 +277,14 @@ impl MessageType for ResponseHead {
|
||||||
|
|
||||||
(len, version, status, res.headers.len())
|
(len, version, status, res.headers.len())
|
||||||
}
|
}
|
||||||
httparse::Status::Partial => return Ok(None),
|
httparse::Status::Partial => return {
|
||||||
|
if src.len() >= MAX_BUFFER_SIZE {
|
||||||
|
error!("MAX_BUFFER_SIZE unprocessed data reached, closing");
|
||||||
|
Err(ParseError::TooLarge)
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -295,9 +300,6 @@ impl MessageType for ResponseHead {
|
||||||
} else if status == StatusCode::SWITCHING_PROTOCOLS {
|
} else if status == StatusCode::SWITCHING_PROTOCOLS {
|
||||||
// switching protocol or connect
|
// switching protocol or connect
|
||||||
PayloadType::Stream(PayloadDecoder::eof())
|
PayloadType::Stream(PayloadDecoder::eof())
|
||||||
} else if src.len() >= MAX_BUFFER_SIZE {
|
|
||||||
error!("MAX_BUFFER_SIZE unprocessed data reached, closing");
|
|
||||||
return Err(ParseError::TooLarge);
|
|
||||||
} else {
|
} else {
|
||||||
// for HTTP/1.0 read to eof and close connection
|
// for HTTP/1.0 read to eof and close connection
|
||||||
if msg.version == Version::HTTP_10 {
|
if msg.version == Version::HTTP_10 {
|
||||||
|
|
|
@ -27,12 +27,12 @@ use crate::service::HttpFlow;
|
||||||
use crate::OnConnectData;
|
use crate::OnConnectData;
|
||||||
|
|
||||||
use super::codec::Codec;
|
use super::codec::Codec;
|
||||||
|
use super::decoder::MAX_BUFFER_SIZE;
|
||||||
use super::payload::{Payload, PayloadSender, PayloadStatus};
|
use super::payload::{Payload, PayloadSender, PayloadStatus};
|
||||||
use super::{Message, MessageType};
|
use super::{Message, MessageType};
|
||||||
|
|
||||||
const LW_BUFFER_SIZE: usize = 1024;
|
const LW_BUFFER_SIZE: usize = 1024;
|
||||||
const HW_BUFFER_SIZE: usize = 1024 * 8;
|
const HW_BUFFER_SIZE: usize = 1024 * 8;
|
||||||
pub(crate) const MAX_HW_BUFFER_SIZE: usize = HW_BUFFER_SIZE * 4;
|
|
||||||
const MAX_PIPELINED_MESSAGES: usize = 16;
|
const MAX_PIPELINED_MESSAGES: usize = 16;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -911,7 +911,7 @@ where
|
||||||
} else {
|
} else {
|
||||||
// If buf is full return but do not disconnect since
|
// If buf is full return but do not disconnect since
|
||||||
// there is more reading to be done
|
// there is more reading to be done
|
||||||
if buf.len() >= MAX_HW_BUFFER_SIZE {
|
if buf.len() >= MAX_BUFFER_SIZE {
|
||||||
return Ok(Some(false));
|
return Ok(Some(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue