📝 Add annotations to HTTP middleware example (#11530)

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Gabriel 2025-06-17 06:48:10 -04:00 committed by GitHub
parent 9957956ef8
commit dfe9dde982
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -4515,14 +4515,17 @@ class FastAPI(Starlette):
```python ```python
import time import time
from typing import Awaitable, Callable
from fastapi import FastAPI, Request from fastapi import FastAPI, Request, Response
app = FastAPI() app = FastAPI()
@app.middleware("http") @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() start_time = time.time()
response = await call_next(request) response = await call_next(request)
process_time = time.time() - start_time process_time = time.time() - start_time