use max_request_size in axum.rs

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-19 23:38:01 -04:00 committed by June
parent 999cc7ccf5
commit 19255c0c14

View file

@ -41,8 +41,6 @@ struct QueryParams {
user_id: Option<String>, user_id: Option<String>,
} }
const MAX_BODY_SIZE: usize = 1024 * 1024 * 128; //TODO: conf?
#[async_trait] #[async_trait]
impl<T, S> FromRequest<S, axum::body::Body> for Ruma<T> impl<T, S> FromRequest<S, axum::body::Body> for Ruma<T>
where where
@ -54,7 +52,15 @@ where
async fn from_request(req: Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> { async fn from_request(req: Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> {
let limited = req.with_limited_body(); let limited = req.with_limited_body();
let (mut parts, body) = limited.into_parts(); let (mut parts, body) = limited.into_parts();
let mut body = axum::body::to_bytes(body, MAX_BODY_SIZE) let mut body = axum::body::to_bytes(
body,
services()
.globals
.config
.max_request_size
.try_into()
.expect("failed to convert max request size"),
)
.await .await
.map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?; .map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?;