Coverage for docs_src / middleware / tutorial001_py310.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import time 1abcd

2 

3from fastapi import FastAPI, Request 1abcd

4 

5app = FastAPI() 1abcd

6 

7 

8@app.middleware("http") 1abcd

9async def add_process_time_header(request: Request, call_next): 1abcd

10 start_time = time.perf_counter() 1efghij

11 response = await call_next(request) 1efghij

12 process_time = time.perf_counter() - start_time 1efghij

13 response.headers["X-Process-Time"] = str(process_time) 1efghij

14 return response 1efghij