Skip to content

Commit

Permalink
Make @removeslash a no-op when applied to a request for '/'.
Browse files Browse the repository at this point in the history
This prevents a redirect loop as browsers interpret an empty redirect
as a redirect to /.
  • Loading branch information
bdarnell committed Feb 12, 2011
1 parent 73d3c82 commit 88833c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tornado/web.py
Expand Up @@ -954,10 +954,12 @@ def wrapper(self, *args, **kwargs):
if self.request.path.endswith("/"):
if self.request.method in ("GET", "HEAD"):
uri = self.request.path.rstrip("/")
if self.request.query: uri += "?" + self.request.query
self.redirect(uri)
return
raise HTTPError(404)
if uri: # don't try to redirect '/' to ''
if self.request.query: uri += "?" + self.request.query
self.redirect(uri)
return
else:
raise HTTPError(404)
return method(self, *args, **kwargs)
return wrapper

Expand Down

0 comments on commit 88833c1

Please sign in to comment.