cookie#

class starlite.datastructures.cookie.Cookie#

Bases: object

Container class for defining a cookie using the ‘Set-Cookie’ header.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie for more details regarding this header.

key: str#

Key for the cookie.

path: str = '/'#

Path fragment that must exist in the request url for the cookie to be valid.

Defaults to ‘/’.

value: Optional[str] = None#

Value for the cookie, if none given defaults to empty string.

max_age: Optional[int] = None#

Maximal age of the cookie before its invalidated.

expires: Optional[int] = None#

Expiration date as unix MS timestamp.

domain: Optional[str] = None#

Domain for which the cookie is valid.

secure: Optional[bool] = None#

Https is required for the cookie.

httponly: Optional[bool] = None#

Forbids javascript to access the cookie via ‘Document.cookie’.

__init__(key: str, path: str = '/', value: Optional[str] = None, max_age: Optional[int] = None, expires: Optional[int] = None, domain: Optional[str] = None, secure: Optional[bool] = None, httponly: Optional[bool] = None, samesite: Literal['lax', 'strict', 'none'] = 'lax', description: Optional[str] = None, documentation_only: bool = False) None#
samesite: Literal['lax', 'strict', 'none'] = 'lax'#

Controls whether or not a cookie is sent with cross-site requests.

Defaults to ‘lax’.

description: Optional[str] = None#

Description of the response cookie header for OpenAPI documentation.

documentation_only: bool = False#

Defines the Cookie instance as for OpenAPI documentation purpose only.

Get a simple cookie object from the values.

Returns:

A SimpleCookie instance.

to_header(**kwargs: Any) str#

Return a string representation suitable to be sent as HTTP headers.

Parameters:

**kwargs – Any kwargs to pass to the simple cookie output method.

to_encoded_header() Tuple[bytes, bytes]#

Create encoded header for ASGI send.

Returns:

A two tuple of bytes.

property dict: Dict[str, Any]#

Get the cookie as a dict.

Returns:

A dict of values

__eq__(other: Any) bool#

Determine whether two cookie instances are equal according to the cookie spec, i.e. hey have a similar path, domain and key.

Parameters:

other – An arbitrary value

Returns:

A boolean