Files
fastapi__fastapi/docs_src/middleware/tutorial001.py
T

15 lines
365 B
Python
Raw Normal View History

2019-04-21 19:56:20 +04:00
import time
from fastapi import FastAPI, Request
2019-04-21 19:56:20 +04:00
app = FastAPI()
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.perf_counter()
2019-04-21 19:56:20 +04:00
response = await call_next(request)
process_time = time.perf_counter() - start_time
2019-04-21 19:56:20 +04:00
response.headers["X-Process-Time"] = str(process_time)
return response