Skip to content

ccproxy.api.middleware.request_content_logging

ccproxy.api.middleware.request_content_logging

Request content logging middleware for capturing full HTTP request/response data.

RequestContentLoggingMiddleware

RequestContentLoggingMiddleware(app)

Bases: BaseHTTPMiddleware

Middleware for logging full HTTP request and response content.

Parameters:

Name Type Description Default
app ASGIApp

The ASGI application

required
Source code in ccproxy/api/middleware/request_content_logging.py
def __init__(self, app: ASGIApp):
    """Initialize the request content logging middleware.

    Args:
        app: The ASGI application
    """
    super().__init__(app)

dispatch async

dispatch(request, call_next)

Process the request and log content.

Parameters:

Name Type Description Default
request Request

The incoming HTTP request

required
call_next Any

The next middleware/handler in the chain

required

Returns:

Type Description
Any

The HTTP response

Source code in ccproxy/api/middleware/request_content_logging.py
async def dispatch(self, request: Request, call_next: Any) -> Any:
    """Process the request and log content.

    Args:
        request: The incoming HTTP request
        call_next: The next middleware/handler in the chain

    Returns:
        The HTTP response
    """
    # Get request ID and timestamp from context if available
    request_id = self._get_request_id(request)
    timestamp = self._get_timestamp_prefix(request)

    # Log incoming request
    await self._log_request(request, request_id, timestamp)

    # Process the request
    response = await call_next(request)

    # Log outgoing response
    await self._log_response(response, request_id, timestamp)

    return response