mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-17 21:06:42 -04:00
📝 Update source examples and docs from Python 3.9 to 3.10 (#14900)
This commit is contained in:
committed by
GitHub
parent
d06ab3f5c7
commit
c9e2277d8b
14
docs_src/middleware/tutorial001_py310.py
Normal file
14
docs_src/middleware/tutorial001_py310.py
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
Reference in New Issue
Block a user