mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
Run middleware for requests with no matching route (#422)
While thinking about #419 I realized that `main` had a bug where middleware wouldn't be called if no route matched the incoming request. `Router` would just directly return a 404 without calling any middleware. This fixes by making the fallback default to a service that always returns 404 and always calling that if no route matches. Layers applied to the router is then also applied to the fallback. Unfortunately this breaks #380 but I don't currently see a way to support both. Auth middleware need to run _after_ routing because you don't care about auth for unknown paths, but logging middleware need to run _before_ routing because they do care about seeing requests for unknown paths so they can log them... Part of #419
This commit is contained in:
@@ -41,9 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **fixed:** Adding a conflicting route will now cause a panic instead of silently making
|
||||
a route unreachable.
|
||||
- **fixed:** Route matching is faster as number of routes increase.
|
||||
- **fixed:** Middleware that return early (such as `tower_http::auth::RequireAuthorization`)
|
||||
now no longer catch requests that would otherwise be 404s. They also work
|
||||
correctly with `Router::merge` (previously called `or`) ([#408])
|
||||
- **fixed:** Correctly handle trailing slashes in routes:
|
||||
- If a route with a trailing slash exists and a request without a trailing
|
||||
slash is received, axum will send a 301 redirection to the route with the
|
||||
|
||||
Reference in New Issue
Block a user