mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-23 00:00:15 +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
@@ -9,7 +9,7 @@
|
||||
use axum::{
|
||||
body::Bytes,
|
||||
error_handling::HandleErrorLayer,
|
||||
extract::{ContentLengthLimit, Path, State},
|
||||
extract::{DefaultBodyLimit, Path, State},
|
||||
handler::Handler,
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
@@ -25,7 +25,8 @@ use std::{
|
||||
};
|
||||
use tower::{BoxError, ServiceBuilder};
|
||||
use tower_http::{
|
||||
auth::RequireAuthorizationLayer, compression::CompressionLayer, trace::TraceLayer,
|
||||
auth::RequireAuthorizationLayer, compression::CompressionLayer, limit::RequestBodyLimitLayer,
|
||||
trace::TraceLayer,
|
||||
};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
@@ -48,7 +49,12 @@ async fn main() {
|
||||
// Add compression to `kv_get`
|
||||
get(kv_get.layer(CompressionLayer::new()))
|
||||
// But don't compress `kv_set`
|
||||
.post(kv_set),
|
||||
.post_service(
|
||||
ServiceBuilder::new()
|
||||
.layer(DefaultBodyLimit::disable())
|
||||
.layer(RequestBodyLimitLayer::new(1024 * 5_000 /* ~5mb */))
|
||||
.service(kv_set.with_state(Arc::clone(&shared_state))),
|
||||
),
|
||||
)
|
||||
.route("/keys", get(list_keys))
|
||||
// Nest our admin routes under `/admin`
|
||||
@@ -94,11 +100,7 @@ async fn kv_get(
|
||||
}
|
||||
}
|
||||
|
||||
async fn kv_set(
|
||||
Path(key): Path<String>,
|
||||
State(state): State<SharedState>,
|
||||
ContentLengthLimit(bytes): ContentLengthLimit<Bytes, { 1024 * 5_000 }>, // ~5mb
|
||||
) {
|
||||
async fn kv_set(Path(key): Path<String>, State(state): State<SharedState>, bytes: Bytes) {
|
||||
state.write().unwrap().db.insert(key, bytes);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user