Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NormalizePath middleware #275

merged 2 commits into from
Jul 12, 2022

Add NormalizePath middleware #275

merged 2 commits into from
Jul 12, 2022


Copy link

In axum we're removing support for trailing slash redirects (see tokio-rs/axum#1118 for more details). That means its a little more work for users if they want their routes to be matched both with and without a trailing slash. This middleware addresses that.

Example usage with axum:

// what you'd have to do without this middleware
    .route("/foo", get(handler))
    .route("/foo/", get(handler));

// using the middleware we only have to add one route
    Router::new().route("/foo", get(handler))

Note that axum's Router::layer cannot be used since routing happens before any middleware are called, thus the requests would 404. That is something we have to address separately in axum but I still think this middleware makes sense on its own.

@davidpdrsn davidpdrsn added the A-new-middleware Area: new middleware proposals label Jun 25, 2022
Copy link

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Copy link
Member Author

I'll fix CI later in a separate PR.

@davidpdrsn davidpdrsn merged commit 77d7148 into master Jul 12, 2022
@davidpdrsn davidpdrsn deleted the normalize-path branch July 12, 2022 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
A-new-middleware Area: new middleware proposals
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants