INNER CODE UNIT · Python

track_upstream_fetches

felipeall/transfermarkt-api · app/main.py:72

async def track_upstream_fetches(request: Request, call_next: RequestResponseEndpoint) -> Response:
    """
    Start a per-request record of upstream fetch times, used for `updatedAt`, and log the request.

    Replaces uvicorn's access log, which on Fly.io shows the proxy's address: this one shows `client_ip`.
    """
    track_fetches()
    status = 500
    try:
        response = await call_next(request)
        status = response.status_code
        return response
    finally:
        target = f"{request.url.path}?{request.url.query}" if request.url.query else request.url.path
        access_log.info('%s - "%s %s" %d', client_ip(request), request.method, target, status)


@app.get("/", include_in_schema=False)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…