Spaces:
Sleeping
Sleeping
File size: 511 Bytes
0242ab2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import time
from fastapi import Request
async def request_timer(
request: Request,
call_next
):
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:.4f}"
print(
f"[{request.method}] "
f"{request.url.path} "
f"completed in "
f"{process_time:.4f}s"
)
return response |