Implement body size limit middleware with dynamic config reload
Add body_limit middleware that reads limit from ArcSwap<DynamicConfig> on each request, enabling runtime config changes without restart. Uses Content-Length header check for fast rejection and http_body_util::Limited for streaming body enforcement. Default limit: 100 MB (104,857,600 bytes). Returns 413 Payload Too Large when exceeded.
This commit is contained in:
@@ -1,3 +1,20 @@
|
||||
pub mod body_limit;
|
||||
pub mod error;
|
||||
pub mod handler;
|
||||
pub mod headers;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
|
||||
use crate::config::DynamicConfig;
|
||||
|
||||
pub fn router_with_body_limit(
|
||||
router: axum::Router,
|
||||
config: Arc<ArcSwap<DynamicConfig>>,
|
||||
) -> axum::Router {
|
||||
router.layer(axum::middleware::from_fn_with_state(
|
||||
config,
|
||||
body_limit::body_limit_middleware,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user