]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add annotations to HTTP middleware example (#11530)
authorGabriel <gabriel59kg@gmail.com>
Tue, 17 Jun 2025 10:48:10 +0000 (06:48 -0400)
committerGitHub <noreply@github.com>
Tue, 17 Jun 2025 10:48:10 +0000 (12:48 +0200)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
fastapi/applications.py

index 7a1db253213e73d411b8da214af45b056662f1ba..05c7bd2be71ce3027a4bbf111d50cd940156384f 100644 (file)
@@ -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