Add DefaultBodyLimit::max to change the body size limit (#1397)

This commit is contained in:
David Pedersen
2022-09-19 22:41:54 +02:00
committed by GitHub
parent 7105805ba2
commit de9909d955
5 changed files with 99 additions and 19 deletions
+25
View File
@@ -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;