use usize for max_request_size config item

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-07 19:59:04 +00:00
parent 5af880e4f4
commit 113a27c1d5
5 changed files with 6 additions and 21 deletions

View file

@ -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<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> {
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),
})
}

View file

@ -29,12 +29,7 @@ pub(super) async fn from(request: hyper::Request<axum::body::Body>) -> Result<Re
let query = serde_html_form::from_str(parts.uri.query().unwrap_or_default())
.map_err(|_| Error::BadRequest(ErrorKind::Unknown, "Failed to read query parameters"))?;
let max_body_size = services()
.globals
.config
.max_request_size
.try_into()
.expect("failed to convert max request size");
let max_body_size = services().globals.config.max_request_size;
let body = axum::body::to_bytes(body, max_body_size)
.await

View file

@ -114,7 +114,7 @@ pub struct Config {
pub ip_lookup_strategy: u8,
#[serde(default = "default_max_request_size")]
pub max_request_size: u32,
pub max_request_size: usize,
#[serde(default = "default_max_fetch_prev_events")]
pub max_fetch_prev_events: u16,
@ -930,7 +930,7 @@ fn default_dns_timeout() -> 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
}

View file

@ -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)]

View file

@ -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 }