Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2813,13 +2813,15 @@ def abort(code=500, text='Unknown Error.'):
raise HTTPError(code, text)


def redirect(url, code=None):
def redirect(url, code=None, cache=None):
""" Aborts execution and causes a 303 or 302 redirect, depending on
the HTTP protocol version. """
if not code:
code = 303 if request.get('SERVER_PROTOCOL') == "HTTP/1.1" else 302
res = response.copy(cls=HTTPResponse)
res.status = code
if type(cache) is int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check if the variable exists, you don't need to look at its type.
If it is an unexpected string it will be the developer's responsibility

res.set_header('Cache-Control', 'max-age=%s' % cache)
res.body = ""
res.set_header('Location', urljoin(request.url, url))
raise res
Expand Down