Skip to content

AddProcessTimeHeaderMiddleware

Middleware to add a header with the process time to the response.

AddProcessTimeHeaderMiddleware

Bases: BaseHTTPMiddleware

Middleware to add a header with the process time to the response.

Source code in src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py
 9
10
11
12
13
14
15
16
17
18
class AddProcessTimeHeaderMiddleware(BaseHTTPMiddleware):
    """Middleware to add a header with the process time to the response."""

    async def dispatch(self, request: Request, call_next) -> Response:
        """Add a header with the process time to the response."""
        start_time = time.perf_counter()
        response = await call_next(request)
        process_time = time.perf_counter() - start_time
        response.headers["X-Process-Time"] = f"{process_time:.3f}"
        return response

dispatch(request: Request, call_next) -> Response async

Add a header with the process time to the response.

Source code in src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py
12
13
14
15
16
17
18
async def dispatch(self, request: Request, call_next) -> Response:
    """Add a header with the process time to the response."""
    start_time = time.perf_counter()
    response = await call_next(request)
    process_time = time.perf_counter() - start_time
    response.headers["X-Process-Time"] = f"{process_time:.3f}"
    return response