Ligare.web.middleware.context

Functions

extract_content_type(headers)

Extract the mime type and encoding from the content type headers.

get_trace_id()

split_content_type(content_type)

Split the content type in mime_type and encoding.

Classes

CorrelationIdMiddleware(app)

Generate a Correlation ID for each request.

MiddlewareRequestDict

MiddlewareResponseDict

RequestIdMiddleware(app)

Generate a Trace ID for each request.

TraceId(CorrelationId, RequestId)

class Ligare.web.middleware.context.CorrelationIdMiddleware(app)[source]

Generate a Correlation ID for each request.

https://github.com/encode/starlette/issues/420

__init__(app)[source]
class Ligare.web.middleware.context.MiddlewareRequestDict
app: ConnexionMiddleware
client: list[str | int]
extensions: dict[str, dict[str, str]]
headers: list[tuple[bytes, bytes]]
http_version: str
method: Literal['GET', 'POST', 'PATCH', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE']
path: str
path_params: dict[Any, Any]
query_string: bytes
raw_path: bytes
root_path: str
scheme: str
server: list[str | int]
state: dict[Any, Union[Any, dict[Any, Union[Any, AnyDict]]]]
type: Literal['http']
class Ligare.web.middleware.context.MiddlewareResponseDict
headers: list[tuple[bytes, bytes]]
status: int
type: Literal['http.response.start']
class Ligare.web.middleware.context.RequestIdMiddleware(app)[source]

Generate a Trace ID for each request. If X-Correlation-Id is set in the request headers, that ID is used instead.

__init__(app)[source]
class Ligare.web.middleware.context.TraceId(CorrelationId, RequestId)[source]
CorrelationId: Optional[NewType(CorrelationId, str)]

Alias for field number 0

RequestId: Optional[NewType(RequestId, str)]

Alias for field number 1

Ligare.web.middleware.context.extract_content_type(headers)[source]

Extract the mime type and encoding from the content type headers.

Parameters:

headers (list[tuple[bytes, bytes]] | dict[str, str]) – Headers from ASGI scope

Return type:

str | None

Returns:

The content type if available in headers, otherwise None

Ligare.web.middleware.context.get_trace_id()[source]
Return type:

TraceId

Ligare.web.middleware.context.split_content_type(content_type)[source]

Split the content type in mime_type and encoding. Other parameters are ignored.

Return type:

tuple[str | None, str | None]