client_side¶
- members:
- class litestar.middleware.session.client_side.ClientSideSessionBackend[源代码]¶
基类:
BaseSessionBackend[CookieBackendConfig]Cookie backend for SessionMiddleware.
- __init__(config: CookieBackendConfig) None[源代码]¶
Initialize
ClientSideSessionBackend.- 参数:
config¶ -- SessionCookieConfig instance.
- dump_data(data: Any, scope: Scope | None = None) list[bytes][源代码]¶
Given serializable data, including pydantic models and numpy types, dump it into a bytes string, encrypt, encode and split it into chunks of the desirable size.
备注
The returned list is composed of a chunks of a single base64 encoded string that is encrypted using AES-CGM.
- 返回:
List of encoded bytes string of a maximum length equal to the
CHUNK_SIZEconstant.
- load_data(data: list[bytes]) dict[str, Any][源代码]¶
Given a list of strings, decodes them into the session object.
- 参数:
data¶ -- A list of strings derived from the request's session cookie(s).
- 返回:
A deserialized session value.
- get_cookie_keys(connection: ASGIConnection) list[str][源代码]¶
Return a list of cookie-keys from the connection if they match the session-cookie pattern.
- 参数:
connection¶ -- An ASGIConnection instance
- 返回:
A list of session-cookie keys
- get_cookie_key_set(connection: ASGIConnection) set[str][源代码]¶
Return a set of cookie-keys from the connection if they match the session-cookie pattern.
Added in version 2.8.3.
- 参数:
connection¶ -- An ASGIConnection instance
- 返回:
A set of session-cookie keys
- async store_in_message(scope_session: ScopeSession, message: Message, connection: ASGIConnection) None[源代码]¶
Store data from
scope_sessioninMessagein the form of cookies. If the contents ofscope_sessionare too large to fit a single cookie, it will be split across several cookies, following the naming scheme of<cookie key>-<n>. If the session is empty or shrinks, cookies will be cleared by setting their value to"null"
- class litestar.middleware.session.client_side.CookieBackendConfig[源代码]¶
基类:
BaseBackendConfig[ClientSideSessionBackend]Configuration for [SessionMiddleware] middleware.
- secret: bytes¶
A secret key to use for generating an encryption key.
Must have a length of 16 (128 bits), 24 (192 bits) or 32 (256 bits) characters.
- key: str = 'session'¶
Key to use for the cookie inside the header, e.g.
session=<data>wheresessionis the cookie key and<data>is the session data.备注
If a session cookie exceeds 4KB in size it is split. In this case the key will be of the format
session-{segment number}.
- path: str = '/'¶
Path fragment that must exist in the request url for the cookie to be valid.
Defaults to
'/'.
- __init__(secret: bytes, key: str = 'session', max_age: int = 1209600, scopes: set[~typing.Literal[ScopeType.HTTP, ScopeType.WEBSOCKET]] = <factory>, path: str = '/', domain: str | None = None, secure: bool = False, httponly: bool = True, samesite: ~typing.Literal['lax', 'strict', 'none'] = 'lax', exclude: str | list[str] | None = None, exclude_opt_key: str = 'skip_session') None¶
- samesite: Literal['lax', 'strict', 'none'] = 'lax'¶
Controls whether or not a cookie is sent with cross-site requests.
Defaults to
lax.