facebook/tornado — Issue #424: Leave the user to decide witch HTTP redirect code to use
Author: tomo-wang
Created: 2011-12-28 11:38:18+00:00
State: open

The redirect function in RequestHandler class only support 301 and 302 redirect code. I think we should support other HTTP redirect code such as 303 and 307.
I suggest changing the parameter of the redirect function, like add "status" parameter, and leave the user to dicide witch redirect code to use.
To permit backwards compatibility, I'd suggest this:

def redirect(self, url, permanent=False, status=None):
"""Sends a redirect to the given (optionally relative) URL."""
if self._headers_written:
raise Exception("Cannot redirect after headers have been written")
if not status:
self.set_status(301 if permanent else 302)
else:
self.set_status(status)
# Remove whitespace
url = re.sub(r"[\x00-\x20]+", "", _utf8(url))
self.set_header("Location", urlparse.urljoin(self.request.uri, url))
self.finish()