def cookie(self, name, value, path='/', expires=None, max_age=None, domain=None, secure=None, comment=None, version=None, codec=None): """ Set response cookie :Parameters: - `name`: Cookie name - `value`: Cookie value (if a codec is given, the type should be applicable for the codec encoder). - `path`: Valid URL base path for the cookie. It should always be set to a reasonable path (at least ``/``), otherwise the cookie will only be valid for the current URL and below. - `expires`: Expire time of the cookie. If unset or ``None`` the cookie is dropped when the browser is closed. See also the `max_age` parameter. - `max_age`: Max age of the cookie in seconds. If set, make sure it matches the expiry time. The difference is that expires will be transformed to a HTTP date, while max-age will stay an integer. The expires parameter is the older one and better understood by the clients out there. For that reason if you set max_age only, expires will be set automatically to ``now + max_age``. If unset or ``None`` the cookie will be dropped when the browser is closed. - `domain`: Valid domain - `secure`: Whether this is an SSL-only cookie or not - `comment`: Cookie comment - `version`: Cookie spec version. See `RFC 2965`_ - `codec`: Cookie codec to apply. If unset or ``None``, the codec specified in the application configuration is applied. .. _RFC 2965: http://www.ietf.org/rfc/rfc2965.txt :Types: - `name`: ``str`` - `value`: ``str`` - `path`: ``str`` - `expires`: ``datetime.datetime`` - `max_age`: ``int`` - `domain`: ``str`` - `secure`: ``bool`` - `comment`: ``str`` - `version`: ``int`` - `codec`: `CookieCodecInterface` """ # pylint: disable = R0913 if codec is None: codec = self.request.env.get('wtf.codec.cookie') cstring = _httputil.make_cookie(name, value, codec, path=path, expires=expires, max_age=max_age, domain=domain, secure=secure, comment=comment, version=version ) self.headers.add('Set-Cookie', cstring)
def make_cookie(self): """ :See: `wtf.app.services.session.StorageInterface.make_cookie` """ return _httputil.make_cookie(value=self._sid, **self.cookie)