feat: add QUERY method routing (#3801)

This commit is contained in:
Yunus
2026-08-03 21:29:39 +02:00
committed by GitHub
parent 98884fb7be
commit a2e64a8fc3
9 changed files with 78 additions and 16 deletions
+2
View File
@@ -22,11 +22,13 @@ and this project adheres to [Semantic Versioning].
.route_with_tsr("/path", get(/* handler */))
.route_with_tsr("/path", post(/* handler */))
```
- **added:** Add `RouterExt::typed_query` ([#3801])
- **fixed:** Escape multipart `Content-Disposition` parameters and reject
newlines in field names and filenames ([#3776])
[#3599]: https://github.com/tokio-rs/axum/pull/3599
[#3586]: https://github.com/tokio-rs/axum/pull/3586
[#3801]: https://github.com/tokio-rs/axum/pull/3801
[#3776]: https://github.com/tokio-rs/axum/pull/3776
# 0.12.6
+23
View File
@@ -234,6 +234,19 @@ pub trait RouterExt<S>: sealed::Sealed {
T: SecondElementIs<P> + 'static,
P: TypedPath;
/// Add a typed `QUERY` route to the router.
///
/// The path will be inferred from the first argument to the handler function which must
/// implement [`TypedPath`].
///
/// See [`TypedPath`] for more details and examples.
#[cfg(feature = "typed-routing")]
fn typed_query<H, T, P>(self, handler: H) -> Self
where
H: axum::handler::Handler<T, S>,
T: SecondElementIs<P> + 'static,
P: TypedPath;
/// Add another route to the router with an additional "trailing slash redirect" route.
///
/// If you add a route _without_ a trailing slash, such as `/foo`, this method will also add a
@@ -368,6 +381,16 @@ where
self.route(P::PATH, axum::routing::connect(handler))
}
#[cfg(feature = "typed-routing")]
fn typed_query<H, T, P>(self, handler: H) -> Self
where
H: axum::handler::Handler<T, S>,
T: SecondElementIs<P> + 'static,
P: TypedPath,
{
self.route(P::PATH, axum::routing::query(handler))
}
#[track_caller]
fn route_with_tsr(mut self, path: &str, method_router: MethodRouter<S>) -> Self
where