Middleware
provide.foundation.transport.middleware
¶
TODO: Add module docstring.
Classes¶
LoggingMiddleware
¶
Bases: Middleware
Built-in telemetry middleware using foundation.logger.
Functions¶
process_error
async
¶
Log errors.
Source code in provide/foundation/transport/middleware.py
process_request
async
¶
Log outgoing request.
Source code in provide/foundation/transport/middleware.py
process_response
async
¶
Log incoming response.
Source code in provide/foundation/transport/middleware.py
MetricsMiddleware
¶
Bases: Middleware
Middleware for collecting transport metrics using foundation.metrics.
Functions¶
__attrs_post_init__
¶
Initialize metrics after creation.
Source code in provide/foundation/transport/middleware.py
process_error
async
¶
Record error metrics.
Source code in provide/foundation/transport/middleware.py
process_request
async
¶
process_response
async
¶
Record response metrics.
Source code in provide/foundation/transport/middleware.py
Middleware
¶
MiddlewarePipeline
¶
Pipeline for executing middleware in order.
Functions¶
add
¶
process_error
async
¶
Process error through all middleware.
process_request
async
¶
Process request through all middleware.
process_response
async
¶
Process response through all middleware (in reverse order).
Source code in provide/foundation/transport/middleware.py
remove
¶
Remove middleware by class type.
Source code in provide/foundation/transport/middleware.py
RetryMiddleware
¶
Bases: Middleware
Automatic retry middleware using unified retry logic.
Functions¶
execute_with_retry
async
¶
execute_with_retry(
execute_func: Callable[[Request], Awaitable[Response]],
request: Request,
) -> Response
Execute request with retry logic using unified RetryExecutor.
Source code in provide/foundation/transport/middleware.py
process_error
async
¶
Handle error, potentially with retries (this is called by client).
process_request
async
¶
process_response
async
¶
Functions¶
create_default_pipeline
¶
create_default_pipeline(
enable_retry: bool = True,
enable_logging: bool = True,
enable_metrics: bool = True,
) -> MiddlewarePipeline
Create pipeline with default middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_retry
|
bool
|
Enable automatic retry middleware (default: True) |
True
|
enable_logging
|
bool
|
Enable request/response logging middleware (default: True) |
True
|
enable_metrics
|
bool
|
Enable metrics collection middleware (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
MiddlewarePipeline
|
Configured middleware pipeline |
Source code in provide/foundation/transport/middleware.py
get_middleware_by_category
¶
Get all middleware for a category, sorted by priority.
Source code in provide/foundation/transport/middleware.py
register_middleware
¶
register_middleware(
name: str,
middleware_class: type[Middleware],
category: str = "transport.middleware",
**metadata: str | int | bool | None
) -> None
Register middleware in the Hub.