-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
Description
I have a growing list of Pando monkey patches in Liberapay that should be moved upstream if possible.
-
Request.source
: an IP address that can be used in rate limiting, requires a newwebsite.trusted_proxies
attribute as well as theipaddress
package for python < 3.3 -
Response.encode_url(url)
: static method used byResponse.redirect()
, doesn't have to be part of a class once moved upstream -
Response.error(code, msg='')
: modifies the response and raises it -
Response.success(code=200, msg='')
: same as above except thatcode
defaults to 200 -
Response.json(obj, code=200)
: same as above except thatobj
is serialized to JSON and theContent-Type
header is set toapplication/json
-
Response.sanitize_untrusted_url(url)
: prevents XSS attacks -
Response.redirect(url, code=302, trusted_url=True)
: raises the response after modifying its code, setting theLocation
header, and sanitizing the URL iftrusted_url
is set toFalse
-
Response.render(path, state, **extra)
: renders the resourcepath
(e.g.templates/confirm.spt
) withstate
plusextra
as context, sort of an internal redirect -
Response.set_cookie(key, value, expires=None, httponly=True, path='/')
: self-explanatory -
Response.erase_cookie(key, **kw)
: shortcut forset_cookie()
with an empty value and an expiration date in the past -
Response.text
: the decoded body of the response, useful in tests
elegaanz and chadwhitacre