diff --git a/axum-core/src/extract/default_body_limit.rs b/axum-core/src/extract/default_body_limit.rs index 21616287..9b9aa825 100644 --- a/axum-core/src/extract/default_body_limit.rs +++ b/axum-core/src/extract/default_body_limit.rs @@ -11,10 +11,65 @@ use tower_layer::Layer; /// Note that if an extractor consumes the body directly with [`Body::data`], or similar, the /// default limit is _not_ applied. /// +/// # Difference between `DefaultBodyLimit` and [`RequestBodyLimit`] +/// +/// `DefaultBodyLimit` and [`RequestBodyLimit`] serve similar functions but in different ways. +/// +/// `DefaultBodyLimit` is local in that it only applies to [`FromRequest`] implementations that +/// explicitly apply it (or call another extractor that does). You can apply the limit with +/// [`RequestExt::with_limited_body`] or [`RequestExt::into_limited_body`] +/// +/// [`RequestBodyLimit`] is applied globally to all requests, regardless of which extractors are +/// used or how the body is consumed. +/// +/// `DefaultBodyLimit` is also easier to integrate into an existing setup since it doesn't change +/// the request body type: +/// +/// ``` +/// use axum::{ +/// Router, +/// routing::post, +/// body::Body, +/// extract::{DefaultBodyLimit, RawBody}, +/// http::Request, +/// }; +/// +/// let router = Router::new() +/// .route( +/// "/", +/// // even with `DefaultBodyLimit` the request body is still just `Body` +/// post(|request: Request
| async {}), +/// ) +/// .layer(DefaultBodyLimit::max(1024)); +/// ``` +/// +/// ``` +/// use axum::{Router, routing::post, body::Body, extract::RawBody, http::Request}; +/// use tower_http::limit::RequestBodyLimitLayer; +/// use http_body::Limited; +/// +/// let router = Router::new() +/// .route( +/// "/", +/// // `RequestBodyLimitLayer` changes the request body type to `Limited` +/// // extracting a different body type wont work +/// post(|request: Request