-
Notifications
You must be signed in to change notification settings - Fork 38
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
redirect *from* trailing slash #299
Comments
So the rule is simple and up front: if it ends in a trailing slash, strip that and redirect to the non-trailing slash version? Then hitting /foo/bar/ will redirect to /foo/bar which could be /foo/bar.spt or /foo/bar/index.spt or whatever. What about conflicts? what if there's both a /foo/bar.spt and a /foo/bar/index.spt - which gets /foo/bar dispatched to it? |
Yes. I would see this as another small algorithm function (
Most specific wins ... so, |
Iirc, this affects how browsers interpret |
We care - what's the common case? If you're writing an indexfile ( |
Discussing on March call. The question here is raised by the new (with the move to the
|
We trailed off with this discussion. Revisit again later. |
We should have a master chart like the above for the whole of our dispatch, tied to test cases. |
@pjz Link the new spreadsheet here, ya? |
Ah, right, the WIP google-doc spreadsheet is here. Once more final, it should be turned into a document in the repo so tests can be run to make sure the code conforms to the spec. |
I moved the google doc data into a testtable branch, along with some preliminary code that parses it out of the reStructuredText table it's in now. That format was chosen for ease of inclusion into docs - it could (should?) be pulled into a docstring for future consumption by Sphinx. |
Okay, so there's now a test that runs and checks that the table is correct ; the output of the latest branch is at https://travis-ci.org/gittip/aspen-python/jobs/27130417 ; to understand an error, read it and interpret it in the context of the 'files' variable above. Now that there's context, I'm coming to the conclusion that |
@pjz Woo-hoo! Awesome! :D Is dispatch w/ |
Okay, so, to explain as much to me as to you: Currently we iterate through the segments of a request path from left to right, descending on exact match or saving variables for wildcards or whatever. So: the decision at each level of what file/directory to use is made independent of other levels... almost. There's an exception that we remember if we've encountered a wildcard-file along the way so that |
Well the previous message helped some, so here's another: Since we added |
Action item here is to add this to def redirect_from_trailing_slash(request):
path = request.line.uri.path.raw
if path.endswith('/'):
request.redirect(path[:-1]) # + qs With a docstring for how to use it: |
And note that |
Possibly we can inspect |
The result I want is to end up on |
I.e., I don't want to be on |
Another idea: subclass |
How can we use the dispatch table to drive this? |
Something like ... ? def redirect_from_trailing_slash(request, exception=None):
if exception is not None and not isinstance(exception, RedirectToTrailingSlash):
return
path = request.line.uri.path.raw
if path.endswith('/'):
request.redirect(path[:-1]) # + qs |
I think the solution is, as you mentioned, to subclass def redirect_from_trailing_slash(request, exception=None):
if exception is not None:
if isinstance(exception, RedirectToTrailingSlash):
raise FileNotFound
return
path = request.line.uri.path.raw
if path.endswith('/'):
request.redirect(path[:-1]) # + qs |
Whatever the solution, it can now be pretty easily implemented in the algorithm. |
Right now we redirect to trailing slash, so if you hit
/foo/bar
andbar
is a directory, then we redirect to/foo/bar/
. I propose that we switch that behavior around, so that/foo/bar/
always redirects to/foo/bar
.The text was updated successfully, but these errors were encountered: