diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 3cf9b3476..5ac5d906d 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -14,7 +14,7 @@ use crate::header::HeaderMap; use crate::message::{ConnectionType, ResponseHead}; 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; /// Incoming message decoder @@ -204,7 +204,8 @@ impl MessageType for Request { (len, method, uri, version, req.headers.len()) } 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) } else { Ok(None) @@ -228,9 +229,6 @@ impl MessageType for Request { PayloadLength::None => { if method == Method::CONNECT { PayloadType::Stream(PayloadDecoder::eof()) - } else if src.len() >= MAX_BUFFER_SIZE { - trace!("MAX_BUFFER_SIZE unprocessed data reached, closing"); - return Err(ParseError::TooLarge); } else { PayloadType::None } @@ -279,7 +277,14 @@ impl MessageType for ResponseHead { (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 { // switching protocol or connect PayloadType::Stream(PayloadDecoder::eof()) - } else if src.len() >= MAX_BUFFER_SIZE { - error!("MAX_BUFFER_SIZE unprocessed data reached, closing"); - return Err(ParseError::TooLarge); } else { // for HTTP/1.0 read to eof and close connection if msg.version == Version::HTTP_10 { diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index db2393d57..fbd4acc92 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -27,12 +27,12 @@ use crate::service::HttpFlow; use crate::OnConnectData; use super::codec::Codec; +use super::decoder::MAX_BUFFER_SIZE; use super::payload::{Payload, PayloadSender, PayloadStatus}; use super::{Message, MessageType}; const LW_BUFFER_SIZE: usize = 1024; 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; bitflags! { @@ -911,7 +911,7 @@ where } else { // If buf is full return but do not disconnect since // there is more reading to be done - if buf.len() >= MAX_HW_BUFFER_SIZE { + if buf.len() >= MAX_BUFFER_SIZE { return Ok(Some(false)); }