axum icon indicating copy to clipboard operation
axum copied to clipboard

`#[debug_handler]` for from_fn middleware

Open nipunn1313 opened this issue 1 year ago • 3 comments

  • [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.

nipunn1313 avatar May 03 '23 22:05 nipunn1313