mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-06 13:08:12 -05:00
16 lines
379 B
Python
16 lines
379 B
Python
import time
|
|
|
|
from fastapi import FastAPI
|
|
from starlette.requests import Request
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.middleware("http")
|
|
async def add_process_time_header(request: Request, call_next):
|
|
start_time = time.time()
|
|
response = await call_next(request)
|
|
process_time = time.time() - start_time
|
|
response.headers["X-Process-Time"] = str(process_time)
|
|
return response
|