From: Gabriel Date: Tue, 17 Jun 2025 10:48:10 +0000 (-0400) Subject: 📝 Add annotations to HTTP middleware example (#11530) X-Git-Tag: 0.115.13~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dfe9dde982fe63261aecc13f564670b82011846c;p=thirdparty%2Ffastapi%2Ffastapi.git 📝 Add annotations to HTTP middleware example (#11530) Co-authored-by: Sofie Van Landeghem Co-authored-by: Sebastián Ramírez --- diff --git a/fastapi/applications.py b/fastapi/applications.py index 7a1db25321..05c7bd2be7 100644 --- a/fastapi/applications.py +++ b/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