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:
Marek Kuskowski
2022-09-24 11:29:53 +00:00
committed by GitHub
co-authored by David Pedersen
parent c3f3db79ec
commit 896ffc5fba
13 changed files with 33 additions and 383 deletions
+10 -8
View File
@@ -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);
}