Coverage for docs_src / middleware / tutorial001_py310.py: 100%
10 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import time 1abcd
3from fastapi import FastAPI, Request 1abcd
5app = FastAPI() 1abcd
8@app.middleware("http") 1abcd
9async def add_process_time_header(request: Request, call_next): 1abcd
10 start_time = time.perf_counter() 1efghijkl
11 response = await call_next(request) 1efghijkl
12 process_time = time.perf_counter() - start_time 1efghijkl
13 response.headers["X-Process-Time"] = str(process_time) 1efghijkl
14 return response 1efghijkl