mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
15 lines
365 B
Python
15 lines
365 B
Python
import time
|
|
|
|
from fastapi import FastAPI, Request
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.middleware("http")
|
|
async def add_process_time_header(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"] = str(process_time)
|
|
return response
|