return self.request.cookies
def get_cookie(self, name, default=None):
- """Gets the value of the cookie with the given name, else default."""
+ """Returns the value of the request cookie with the given name.
+
+ If the named cookie is not present, returns ``default``.
+
+ This method only returns cookies that were present in the request.
+ It does not see the outgoing cookies set by `set_cookie` in this
+ handler.
+ """
if self.request.cookies is not None and name in self.request.cookies:
return self.request.cookies[name].value
return default
def set_cookie(self, name, value, domain=None, expires=None, path="/",
expires_days=None, **kwargs):
- """Sets the given cookie name/value with the given options.
+ """Sets an outgoing cookie name/value with the given options.
+
+ Newly-set cookies are not immediately visible via `get_cookie`;
+ they are not present until the next request.
- Additional keyword arguments are set on the Cookie.Morsel
+ Additional keyword arguments are set on the cookies.Morsel
directly.
- See https://docs.python.org/2/library/cookie.html#Cookie.Morsel
+ See https://docs.python.org/3/library/http.cookies.html#http.cookies.Morsel
for available attributes.
"""
# The cookie library only accepts type str, in both python 2 and 3
path and domain to clear a cookie as were used when that cookie
was set (but there is no way to find out on the server side
which values were used for a given cookie).
+
+ Similar to `set_cookie`, the effect of this method will not be
+ seen until the following request.
"""
expires = datetime.datetime.utcnow() - datetime.timedelta(days=365)
self.set_cookie(name, value="", path=path, expires=expires,
See `clear_cookie` for more information on the path and domain
parameters.
+ Similar to `set_cookie`, the effect of this method will not be
+ seen until the following request.
+
.. versionchanged:: 3.2
Added the ``path`` and ``domain`` parameters.
Secure cookies may contain arbitrary byte values, not just unicode
strings (unlike regular cookies)
+ Similar to `set_cookie`, the effect of this method will not be
+ seen until the following request.
+
.. versionchanged:: 3.2.1
Added the ``version`` argument. Introduced cookie version 2
The decoded cookie value is returned as a byte string (unlike
`get_cookie`).
+ Similar to `get_cookie`, this method only returns cookies that
+ were present in the request. It does not see outgoing cookies set by
+ `set_secure_cookie` in this handler.
+
.. versionchanged:: 3.2.1
Added the ``min_version`` argument. Introduced cookie version 2;