mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into feat/immutable
This commit is contained in:
commit
0c4b3fcc54
|
@ -191,6 +191,9 @@ fn bytes_to_string(body: Bytes, encoding: &'static Encoding) -> Result<String, E
|
||||||
/// building extractors on top of `Payload`.
|
/// building extractors on top of `Payload`.
|
||||||
///
|
///
|
||||||
/// By default, the payload size limit is 256kB and there is no mime type condition.
|
/// By default, the payload size limit is 256kB and there is no mime type condition.
|
||||||
|
///
|
||||||
|
/// To use this, add an instance of it to your app or service through one of the
|
||||||
|
/// `.app_data()` methods.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PayloadConfig {
|
pub struct PayloadConfig {
|
||||||
limit: usize,
|
limit: usize,
|
||||||
|
@ -198,7 +201,7 @@ pub struct PayloadConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PayloadConfig {
|
impl PayloadConfig {
|
||||||
/// Create new instance with a size limit and no mime type condition.
|
/// Create new instance with a size limit (in bytes) and no mime type condition.
|
||||||
pub fn new(limit: usize) -> Self {
|
pub fn new(limit: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
limit,
|
limit,
|
||||||
|
@ -206,7 +209,7 @@ impl PayloadConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set maximum accepted payload size. The default limit is 256kB.
|
/// Set maximum accepted payload size in bytes. The default limit is 256kB.
|
||||||
pub fn limit(mut self, limit: usize) -> Self {
|
pub fn limit(mut self, limit: usize) -> Self {
|
||||||
self.limit = limit;
|
self.limit = limit;
|
||||||
self
|
self
|
||||||
|
@ -286,10 +289,12 @@ impl HttpMessageBody {
|
||||||
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {
|
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {
|
||||||
match l.to_str() {
|
match l.to_str() {
|
||||||
Ok(s) => match s.parse::<usize>() {
|
Ok(s) => match s.parse::<usize>() {
|
||||||
Ok(l) if l > DEFAULT_CONFIG_LIMIT => {
|
Ok(l) => {
|
||||||
err = Some(PayloadError::Overflow)
|
if l > DEFAULT_CONFIG_LIMIT {
|
||||||
|
err = Some(PayloadError::Overflow);
|
||||||
|
}
|
||||||
|
length = Some(l)
|
||||||
}
|
}
|
||||||
Ok(l) => length = Some(l),
|
|
||||||
Err(_) => err = Some(PayloadError::UnknownLength),
|
Err(_) => err = Some(PayloadError::UnknownLength),
|
||||||
},
|
},
|
||||||
Err(_) => err = Some(PayloadError::UnknownLength),
|
Err(_) => err = Some(PayloadError::UnknownLength),
|
||||||
|
@ -313,9 +318,11 @@ impl HttpMessageBody {
|
||||||
/// Change max size of payload. By default max size is 256kB
|
/// Change max size of payload. By default max size is 256kB
|
||||||
pub fn limit(mut self, limit: usize) -> Self {
|
pub fn limit(mut self, limit: usize) -> Self {
|
||||||
if let Some(l) = self.length {
|
if let Some(l) = self.length {
|
||||||
if l > limit {
|
self.err = if l > limit {
|
||||||
self.err = Some(PayloadError::Overflow);
|
Some(PayloadError::Overflow)
|
||||||
}
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
}
|
}
|
||||||
self.limit = limit;
|
self.limit = limit;
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue