axum
axum copied to clipboard
`#[debug_handler]` for from_fn middleware
- [x] I have looked for existing issues (including closed) about this
Feature Request
I'd like for something like #[debug_handler]
to work on from_fn middleware (which now supports extractors).
Motivation
Same motivation as debug_handler in the first place - you get arcane errors, particularly if you do the FromRequestParts extractors after the FromRequest extractor by mistake.
Proposal
This almost works out of box, but you get this error with code similar to the example code https://docs.rs/axum/latest/axum/middleware/fn.from_fn.html#example
error: `Request<_>` consumes the request body and thus must be the last argument to the handler function
--> crates/common/src/http/mod.rs:390:10
|
390 | req: http::request::Request<Body>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The issue is that middleware looks something like this, with the next
arg
async fn my_middleware<B>(
request: Request<B>,
next: Next<B>,
) -> Response {
Alternatives
We could make a separate macro for middleware vs reusing the debug_handler macro. No strong preference either way.