-
-
Notifications
You must be signed in to change notification settings - Fork 930
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
Strip trailing slash ( / ) from URL route strings. #633
Comments
Not sure about this myself - seems like a bit too much magic to have by default. But you might want to create a PR with your suggested patch already, so this can be discussed at the code level. |
btw: you can use |
Currently we have behavior so that if: * A `/some-path/`route exists. * A `/some-path` route does not exist. Then if a request to `/some-path` is made, we'll redirect to the trailing slash case. We ought to also handle the converse case, so that if... * A `/some-path`route exists. * A `/some-path/` route does not exist. Then if a request to `/some-path/` is made, we'll redirect to the no trailing slash case. Closes #633
Absolutely, yup. We already handle the converse case, but for some reason I've only got the behavior in one way right now. routes = [
Route('/', PlainTextResponse("home")),
Route('/test/', PlainTextResponse("test")),
# Route('/test', PlainTextResponse("I do not need to be added separately"))
]``` |
* Handle trailing slash redirects properly. Currently we have behavior so that if: * A `/some-path/`route exists. * A `/some-path` route does not exist. Then if a request to `/some-path` is made, we'll redirect to the trailing slash case. We ought to also handle the converse case, so that if... * A `/some-path`route exists. * A `/some-path/` route does not exist. Then if a request to `/some-path/` is made, we'll redirect to the no trailing slash case. Closes #633 * Update routing.py * Update routing.py
Yeah, too bad #707 did not have a test. |
@blueyed it looks like the merge commit caused the regression https://github.com/encode/starlette/pull/704/files#diff-34fba745b50527bfb4245d02afd59246, specifically around line 617 of the old version and 564 of the new version. |
Hey all, an optional trailing slash seems to be pretty standard on most websites, but in Starlette, you must add separate routes to handle them. Example:
Could a
route = route.rstrip("/")
please be added to https://github.com/encode/starlette/blob/master/starlette/routing.py inclass Router
before running the match so these routes don't have to be manually added? Thanks!The text was updated successfully, but these errors were encountered: