From 113a27c1d5b4b3b373577c0124016da00eb5879c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 7 Jul 2024 19:59:04 +0000 Subject: [PATCH] use usize for max_request_size config item Signed-off-by: Jason Volk --- src/api/client/media.rs | 4 ++-- src/api/router/request.rs | 7 +------ src/core/config/mod.rs | 4 ++-- src/router/layers.rs | 10 +--------- src/service/globals/mod.rs | 2 -- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/api/client/media.rs b/src/api/client/media.rs index cfb10c3d..44978caf 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -2,6 +2,7 @@ use std::{io::Cursor, sync::Arc, time::Duration}; +use conduit::{debug, error, utils::math::ruma_from_usize, warn}; use image::io::Reader as ImgReader; use ipaddress::IPAddress; use reqwest::Url; @@ -12,7 +13,6 @@ use ruma::api::client::{ get_media_preview, }, }; -use tracing::{debug, error, warn}; use webpage::HTML; use crate::{ @@ -44,7 +44,7 @@ pub(crate) async fn get_media_config_route( _body: Ruma, ) -> Result { Ok(get_media_config::v3::Response { - upload_size: services().globals.max_request_size().into(), + upload_size: ruma_from_usize(services().globals.config.max_request_size), }) } diff --git a/src/api/router/request.rs b/src/api/router/request.rs index 59639eaa..56c76619 100644 --- a/src/api/router/request.rs +++ b/src/api/router/request.rs @@ -29,12 +29,7 @@ pub(super) async fn from(request: hyper::Request) -> Result u64 { 10 } fn default_ip_lookup_strategy() -> u8 { 5 } -fn default_max_request_size() -> u32 { +fn default_max_request_size() -> usize { 20 * 1024 * 1024 // Default to 20 MB } diff --git a/src/router/layers.rs b/src/router/layers.rs index 4fe35164..db664b38 100644 --- a/src/router/layers.rs +++ b/src/router/layers.rs @@ -138,15 +138,7 @@ fn cors_layer(_server: &Server) -> CorsLayer { .max_age(Duration::from_secs(86400)) } -fn body_limit_layer(server: &Server) -> DefaultBodyLimit { - DefaultBodyLimit::max( - server - .config - .max_request_size - .try_into() - .expect("failed to convert max request size"), - ) -} +fn body_limit_layer(server: &Server) -> DefaultBodyLimit { DefaultBodyLimit::max(server.config.max_request_size) } #[allow(clippy::needless_pass_by_value)] #[tracing::instrument(skip_all)] diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 3c0e66c0..f28299b2 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -201,8 +201,6 @@ impl Service { pub fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() } - pub fn max_request_size(&self) -> u32 { self.config.max_request_size } - pub fn max_fetch_prev_events(&self) -> u16 { self.config.max_fetch_prev_events } pub fn allow_registration(&self) -> bool { self.config.allow_registration }