mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Add DefaultBodyLimit::max to change the body size limit (#1397)
This commit is contained in:
@@ -671,6 +671,31 @@ async fn limited_body_with_content_length() {
|
||||
assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn changing_the_default_limit() {
|
||||
let new_limit = 2;
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", post(|_: Bytes| async {}))
|
||||
.layer(DefaultBodyLimit::max(new_limit));
|
||||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
let res = client
|
||||
.post("/")
|
||||
.body(Body::from("a".repeat(new_limit)))
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
let res = client
|
||||
.post("/")
|
||||
.body(Body::from("a".repeat(new_limit + 1)))
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn limited_body_with_streaming_body() {
|
||||
const LIMIT: usize = 3;
|
||||
|
||||
Reference in New Issue
Block a user