Description
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 with ServeDir
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:
- redirect to trailing slash
- return
index.html
(200) - respond with 404 (not found)
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 effect
Alternatives
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