-
Notifications
You must be signed in to change notification settings - Fork 171
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
Handling trailing slashes for directories #542
Comments
You know that |
My bad. I want to support both paths (with and without a trailing slash). This is currently not possible with |
Okay.. So what does your routing setup look like? I would recommend you try to split it into the pieces where the |
I just want to serve directories under no-slash paths My intention was to serve only paths without trailing slashes and have trailing slash redirect to no slash (opposite of what I have already forked this repository and patched |
Ah, now I understand. Feel free to send a PR, it sounds like it's going to be a pretty simple one. |
Feature Request
I'm willing to implement this if approved
Motivation
I want to support only non-trailing slash paths. To do this I wrap my router with
NormalizePathLayer::trim_trailing_slash().layer
. This however doesn't work well withServeDir
which will always redirect to a trailing slash path for directories (/kita
->/kita/
). Therefore, it's not possible not to have trailing slashes on paths that correspond to directories.Proposal
There are 3 possibilities on how to handle paths without a trailing slash for directories:
index.html
(200)I think an enum of 3 variants should be offered with current behavior (redirect) as the default. Additionally, I think that the 3rd variant would make the
append_index_html_on_directories
deprecated as it would have the same effectAlternatives
A solution where I would rewrite URL in a layer before this service would have to access filesystem to verify that path corresponds to a directory. This would incur unnecessary IO reads so it would be best to handle it directly within
ServeDir
I'm eager to hear other proposals on how to design this API
The text was updated successfully, but these errors were encountered: