mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
Add DefaultBodyLimit::max to change the body size limit (#1397)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
default_body_limit::DefaultBodyLimitDisabled, rejection::*, FromRequest, FromRequestParts,
|
||||
default_body_limit::DefaultBodyLimitKind, rejection::*, FromRequest, FromRequestParts,
|
||||
};
|
||||
use crate::BoxError;
|
||||
use async_trait::async_trait;
|
||||
@@ -88,15 +88,23 @@ where
|
||||
// `axum/src/docs/extract.md` if this changes
|
||||
const DEFAULT_LIMIT: usize = 2_097_152; // 2 mb
|
||||
|
||||
let bytes = if req.extensions().get::<DefaultBodyLimitDisabled>().is_some() {
|
||||
crate::body::to_bytes(req.into_body())
|
||||
let limit_kind = req.extensions().get::<DefaultBodyLimitKind>().copied();
|
||||
let bytes = match limit_kind {
|
||||
Some(DefaultBodyLimitKind::Disable) => crate::body::to_bytes(req.into_body())
|
||||
.await
|
||||
.map_err(FailedToBufferBody::from_err)?
|
||||
} else {
|
||||
let body = http_body::Limited::new(req.into_body(), DEFAULT_LIMIT);
|
||||
crate::body::to_bytes(body)
|
||||
.await
|
||||
.map_err(FailedToBufferBody::from_err)?
|
||||
.map_err(FailedToBufferBody::from_err)?,
|
||||
Some(DefaultBodyLimitKind::Limit(limit)) => {
|
||||
let body = http_body::Limited::new(req.into_body(), limit);
|
||||
crate::body::to_bytes(body)
|
||||
.await
|
||||
.map_err(FailedToBufferBody::from_err)?
|
||||
}
|
||||
None => {
|
||||
let body = http_body::Limited::new(req.into_body(), DEFAULT_LIMIT);
|
||||
crate::body::to_bytes(body)
|
||||
.await
|
||||
.map_err(FailedToBufferBody::from_err)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(bytes)
|
||||
|
||||
Reference in New Issue
Block a user