Browse Source

📝 Add annotations to HTTP middleware example (#11530)

Co-authored-by: Sofie Van Landeghem <[email protected]>
Co-authored-by: Sebastián Ramírez <[email protected]>
pull/13793/merge
Gabriel 2 days ago
committed by GitHub
parent
commit
dfe9dde982
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      fastapi/applications.py

7
fastapi/applications.py

@ -4515,14 +4515,17 @@ class FastAPI(Starlette):
```python
import time
from typing import Awaitable, Callable
from fastapi import FastAPI, Request
from fastapi import FastAPI, Request, Response
app = FastAPI()
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
async def add_process_time_header(
request: Request, call_next: Callable[[Request], Awaitable[Response]]
) -> Response:
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time

Loading…
Cancel
Save