data_extractors¶
- class litestar.data_extractors.ConnectionDataExtractor[原始碼]¶
基底類別:
objectUtility class to extract data from an
ASGIConnection,RequestorWebSocketinstance.- __init__(extract_body: bool = True, extract_client: bool = True, extract_content_type: bool = True, extract_cookies: bool = True, extract_headers: bool = True, extract_method: bool = True, extract_path: bool = True, extract_path_params: bool = True, extract_query: bool = True, extract_scheme: bool = True, obfuscate_cookies: Set[str] | None = None, obfuscate_headers: Set[str] | None = None, parse_body: bool = False, parse_query: bool = False, skip_parse_malformed_body: bool = False) None[原始碼]¶
初始化
ConnectionDataExtractor- 參數:
extract_body¶ -- Whether to extract body, (for requests only).
extract_client¶ -- Whether to extract the client (host, port) mapping.
extract_content_type¶ -- Whether to extract the content type and any options.
extract_cookies¶ -- Whether to extract cookies.
extract_headers¶ -- Whether to extract headers.
extract_method¶ -- Whether to extract the HTTP method, (for requests only).
extract_path¶ -- Whether to extract the path.
extract_path_params¶ -- Whether to extract path parameters.
extract_query¶ -- Whether to extract query parameters.
extract_scheme¶ -- Whether to extract the http scheme.
obfuscate_headers¶ -- headers keys to obfuscate. Obfuscated values are replaced with '*'.
obfuscate_cookies¶ -- cookie keys to obfuscate. Obfuscated values are replaced with '*'.
parse_body¶ -- Whether to parse the body value or return the raw byte string, (for requests only).
parse_query¶ -- Whether to parse query parameters or return the raw byte string.
skip_parse_malformed_body¶ -- Whether to skip parsing the body if it is malformed
- __call__(connection: ASGIConnection[Any, Any, Any, Any]) ExtractedRequestData[原始碼]¶
Extract data from the connection, returning a dictionary of values.
備註
The value for
body- if present - is an unresolved Coroutine and as such should be awaited by the receiver.
- 參數:
connection¶ -- An ASGI connection or its subclasses.
- 回傳:
A string keyed dictionary of extracted values.
- static extract_scheme(connection: ASGIConnection[Any, Any, Any, Any]) str[原始碼]¶
Extract the scheme from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
The connection's scope["scheme"] value
- static extract_client(connection: ASGIConnection[Any, Any, Any, Any]) tuple[str, int][原始碼]¶
Extract the client from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
The connection's scope["client"] value or a default value.
- static extract_path(connection: ASGIConnection[Any, Any, Any, Any]) str[原始碼]¶
Extract the path from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
The connection's scope["path"] value
- extract_headers(connection: ASGIConnection[Any, Any, Any, Any]) dict[str, str][原始碼]¶
Extract headers from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
A dictionary with the connection's headers.
- extract_cookies(connection: ASGIConnection[Any, Any, Any, Any]) dict[str, str][原始碼]¶
Extract cookies from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
A dictionary with the connection's cookies.
- extract_query(connection: ASGIConnection[Any, Any, Any, Any]) Any[原始碼]¶
Extract query from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
Either a dictionary with the connection's parsed query string or the raw query byte-string.
- static extract_path_params(connection: ASGIConnection[Any, Any, Any, Any]) dict[str, Any][原始碼]¶
Extract the path parameters from an
ASGIConnection- 參數:
connection¶ -- An
ASGIConnectioninstance.- 回傳:
A dictionary with the connection's path parameters.
- static extract_method(request: Request[Any, Any, Any]) Method[原始碼]¶
Extract the method from an
ASGIConnection
- class litestar.data_extractors.ExtractedRequestData[原始碼]¶
基底類別:
TypedDictDictionary representing extracted request data.
- class litestar.data_extractors.ExtractedResponseData[原始碼]¶
基底類別:
TypedDictDictionary representing extracted response data.
- class litestar.data_extractors.ResponseDataExtractor[原始碼]¶
基底類別:
objectUtility class to extract data from a
Message- __init__(extract_body: bool = True, extract_cookies: bool = True, extract_headers: bool = True, extract_status_code: bool = True, obfuscate_cookies: Set[str] | None = None, obfuscate_headers: Set[str] | None = None) None[原始碼]¶
Initialize
ResponseDataExtractorwith options.- 參數:
extract_body¶ -- Whether to extract the body.
extract_cookies¶ -- Whether to extract the cookies.
extract_headers¶ -- Whether to extract the headers.
extract_status_code¶ -- Whether to extract the status code.
obfuscate_cookies¶ -- cookie keys to obfuscate. Obfuscated values are replaced with '*'.
obfuscate_headers¶ -- headers keys to obfuscate. Obfuscated values are replaced with '*'.
- __call__(messages: tuple[HTTPResponseStartEvent, HTTPResponseBodyEvent]) ExtractedResponseData[原始碼]¶
Extract data from the response, returning a dictionary of values.
- 參數:
messages¶ -- A tuple containing
HTTPResponseStartEventandHTTPResponseBodyEvent.- 回傳:
A string keyed dictionary of extracted values.
- static extract_response_body(messages: tuple[HTTPResponseStartEvent, HTTPResponseBodyEvent]) bytes[原始碼]¶
Extract the response body from a
Message- 參數:
messages¶ -- A tuple containing
HTTPResponseStartEventandHTTPResponseBodyEvent.- 回傳:
The Response's body as a byte-string.
- static extract_status_code(messages: tuple[HTTPResponseStartEvent, HTTPResponseBodyEvent]) int[原始碼]¶
Extract a status code from a
Message- 參數:
messages¶ -- A tuple containing
HTTPResponseStartEventandHTTPResponseBodyEvent.- 回傳:
The Response's status-code.
- extract_headers(messages: tuple[HTTPResponseStartEvent, HTTPResponseBodyEvent]) dict[str, str][原始碼]¶
Extract headers from a
Message- 參數:
messages¶ -- A tuple containing
HTTPResponseStartEventandHTTPResponseBodyEvent.- 回傳:
The Response's headers dict.
- extract_cookies(messages: tuple[HTTPResponseStartEvent, HTTPResponseBodyEvent]) dict[str, str][原始碼]¶
Extract cookies from a
Message- 參數:
messages¶ -- A tuple containing
HTTPResponseStartEventandHTTPResponseBodyEvent.- 回傳:
The Response's cookies dict.