mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-24 00:00:16 +02:00
Remove ContentLengthLimit (#1400)
* feat: remove ContentLengthLimit * feat: remove ContentLengthLimit rejections * fix: update multipart docs * fix: typo * feat: add wip extractor code * feat: revert "feat: add wip extractor code" * fix: update Multipart docs * fix: update examples * fix: missing import in an example * fix: broken import yet again * fix: disable default body limit for example * fix: key value store example * fix: update expected debug_handler output * chore: update CHANGELOG * Update axum/CHANGELOG.md Co-authored-by: David Pedersen <[email protected]>
This commit is contained in:
co-authored by
David Pedersen
parent
c3f3db79ec
commit
896ffc5fba
@@ -5,12 +5,13 @@
|
||||
//! ```
|
||||
|
||||
use axum::{
|
||||
extract::{ContentLengthLimit, Multipart},
|
||||
extract::{DefaultBodyLimit, Multipart},
|
||||
response::Html,
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
use tower_http::limit::RequestBodyLimitLayer;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -26,6 +27,10 @@ async fn main() {
|
||||
// build our application with some routes
|
||||
let app = Router::new()
|
||||
.route("/", get(show_form).post(accept_form))
|
||||
.layer(DefaultBodyLimit::disable())
|
||||
.layer(RequestBodyLimitLayer::new(
|
||||
250 * 1024 * 1024, /* 250mb */
|
||||
))
|
||||
.layer(tower_http::trace::TraceLayer::new_for_http());
|
||||
|
||||
// run it with hyper
|
||||
@@ -58,14 +63,7 @@ async fn show_form() -> Html<&'static str> {
|
||||
)
|
||||
}
|
||||
|
||||
async fn accept_form(
|
||||
ContentLengthLimit(mut multipart): ContentLengthLimit<
|
||||
Multipart,
|
||||
{
|
||||
250 * 1024 * 1024 /* 250mb */
|
||||
},
|
||||
>,
|
||||
) {
|
||||
async fn accept_form(mut multipart: Multipart) {
|
||||
while let Some(field) = multipart.next_field().await.unwrap() {
|
||||
let name = field.name().unwrap().to_string();
|
||||
let file_name = field.file_name().unwrap().to_string();
|
||||
|
||||
Reference in New Issue
Block a user