INNER CODE UNIT · Python

AuditMiddleware

georgekhananaev/google-reviews-scraper-pro · api_server.py:139

class AuditMiddleware(BaseHTTPMiddleware):
    """Log every request to the API audit table."""

    async def dispatch(self, request: Request, call_next) -> Response:
        start = time.monotonic()
        response = await call_next(request)
        elapsed_ms = int((time.monotonic() - start) * 1000)

        api_key_db = getattr(request.app.state, "api_key_db", None)
        if api_key_db is None:
            return response

        key_info = getattr(request.state, "api_key_info", None) if hasattr(request.state, "api_key_info") else None
        key_id = key_info["id"] if key_info else None
        key_name = key_info["name"] if key_info else None
        client_ip = request.client.host if request.client else None

        try:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…