Skip to content
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

Add an optional redirect(cache=sec) argument #1370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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