mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
Clearly document applying DefaultBodyLimit to individual routes (#2157)
This commit is contained in:
@@ -64,6 +64,28 @@ use tower_layer::Layer;
|
||||
/// extractors and want to sure a limit is also applied there then [`RequestBodyLimit`] should be
|
||||
/// used.
|
||||
///
|
||||
/// # Different limits for different routes
|
||||
///
|
||||
/// `DefaultBodyLimit` can also be selectively applied to have different limits for different
|
||||
/// routes:
|
||||
///
|
||||
/// ```
|
||||
/// use axum::{
|
||||
/// Router,
|
||||
/// routing::post,
|
||||
/// body::Body,
|
||||
/// http::Request,
|
||||
/// extract::DefaultBodyLimit,
|
||||
/// };
|
||||
///
|
||||
/// let app = Router::new()
|
||||
/// // this route has a different limit
|
||||
/// .route("/", post(|request: Request<_>| async {}).layer(DefaultBodyLimit::max(1024)))
|
||||
/// // this route still has the default limit
|
||||
/// .route("/foo", post(|request: Request<_>| async {}));
|
||||
/// # let _: Router = app;
|
||||
/// ```
|
||||
///
|
||||
/// [`Body::data`]: http_body::Body::data
|
||||
/// [`Bytes`]: bytes::Bytes
|
||||
/// [`Json`]: https://docs.rs/axum/0.6.0/axum/struct.Json.html
|
||||
|
||||
Reference in New Issue
Block a user