-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Our timing middleware should report timing via the Server-Timing header1 to better integrate with the Server Timing2 / Performance Server Timing3 APIs
stac-auth-proxy/src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py
Lines 9 to 18 in d3d3769
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 |