fix(main): fix request size limit to max_request_size (axum defaults 2MB)

This commit is contained in:
AndSDev 2022-10-25 12:53:58 +03:00
parent cb2b5beea8
commit 10d2da3009
3 changed files with 13 additions and 7 deletions

8
Cargo.lock generated
View file

@ -109,9 +109,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.5.16" version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e3356844c4d6a6d6467b8da2cffb4a2820be256f50a3a386c9d152bab31043" checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
@ -141,9 +141,9 @@ dependencies = [
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.2.8" version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9f0c0a60006f2a293d82d571f635042a72edf927539b7685bd62d361963839b" checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",

View file

@ -14,7 +14,7 @@ edition = "2021"
[dependencies] [dependencies]
# Web framework # Web framework
axum = { version = "0.5.8", default-features = false, features = ["form", "headers", "http1", "http2", "json", "matched-path"], optional = true } axum = { version = "0.5.17", default-features = false, features = ["form", "headers", "http1", "http2", "json", "matched-path"], optional = true }
axum-server = { version = "0.4.0", features = ["tls-rustls"] } axum-server = { version = "0.4.0", features = ["tls-rustls"] }
tower = { version = "0.4.8", features = ["util"] } tower = { version = "0.4.8", features = ["util"] }
tower-http = { version = "0.3.4", features = ["add-extension", "cors", "compression-full", "sensitive-headers", "trace", "util"] } tower-http = { version = "0.3.4", features = ["add-extension", "cors", "compression-full", "sensitive-headers", "trace", "util"] }

View file

@ -10,7 +10,7 @@
use std::{future::Future, io, net::SocketAddr, time::Duration}; use std::{future::Future, io, net::SocketAddr, time::Duration};
use axum::{ use axum::{
extract::{FromRequest, MatchedPath}, extract::{DefaultBodyLimit, FromRequest, MatchedPath},
handler::Handler, handler::Handler,
response::IntoResponse, response::IntoResponse,
routing::{get, on, MethodFilter}, routing::{get, on, MethodFilter},
@ -164,7 +164,13 @@ async fn run_server() -> io::Result<()> {
header::AUTHORIZATION, header::AUTHORIZATION,
]) ])
.max_age(Duration::from_secs(86400)), .max_age(Duration::from_secs(86400)),
); )
.layer(DefaultBodyLimit::max(
config
.max_request_size
.try_into()
.expect("failed to convert max request size"),
));
let app = routes().layer(middlewares).into_make_service(); let app = routes().layer(middlewares).into_make_service();
let handle = ServerHandle::new(); let handle = ServerHandle::new();