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
merged 2 commits into from
Jul 12, 2022
Merged

Add NormalizePath middleware #275

merged 2 commits into from
Jul 12, 2022

Conversation

davidpdrsn
Copy link
Member

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
Router::new()
    .route("/foo", get(handler))
    .route("/foo/", get(handler));

// using the middleware we only have to add one route
NormalizePath::trim_trailing_slash(
    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
Collaborator

@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.

nice!

@davidpdrsn
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
Labels
A-new-middleware Area: new middleware proposals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants