From 19255c0c14a69b157eedf3425f12c2f105a51acb Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 19 Apr 2024 23:38:01 -0400 Subject: [PATCH] use max_request_size in axum.rs Signed-off-by: strawberry --- src/api/ruma_wrapper/axum.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/api/ruma_wrapper/axum.rs b/src/api/ruma_wrapper/axum.rs index 6246324f..1cfc36b0 100644 --- a/src/api/ruma_wrapper/axum.rs +++ b/src/api/ruma_wrapper/axum.rs @@ -41,8 +41,6 @@ struct QueryParams { user_id: Option, } -const MAX_BODY_SIZE: usize = 1024 * 1024 * 128; //TODO: conf? - #[async_trait] impl FromRequest for Ruma where @@ -54,9 +52,17 @@ where async fn from_request(req: Request, _state: &S) -> Result { let limited = req.with_limited_body(); let (mut parts, body) = limited.into_parts(); - let mut body = axum::body::to_bytes(body, MAX_BODY_SIZE) - .await - .map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?; + let mut body = axum::body::to_bytes( + body, + services() + .globals + .config + .max_request_size + .try_into() + .expect("failed to convert max request size"), + ) + .await + .map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?; let metadata = T::METADATA; let auth_header: Option>> = parts.extract().await?;