From 44df0185d00515e5455d097e2984a8d9bc6136c0 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 3 May 2024 21:21:19 -0400 Subject: [PATCH 1/5] Add annotations --- fastapi/applications.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index 4446cacfb..7fef5a35e 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -4515,6 +4515,7 @@ class FastAPI(Starlette): ```python import time + from typing import Awaitable, Callabe from fastapi import FastAPI, Request @@ -4522,7 +4523,7 @@ class FastAPI(Starlette): @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]): start_time = time.time() response = await call_next(request) process_time = time.time() - start_time From 071ec3f322114530c9dca1525b7d3b11cdccee01 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 3 May 2024 21:24:51 -0400 Subject: [PATCH 2/5] Update applications.py --- fastapi/applications.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index 7fef5a35e..b71107eaa 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -4523,7 +4523,10 @@ class FastAPI(Starlette): @app.middleware("http") - async def add_process_time_header(request: Request, call_next: Callable[[Request], Awaitable[Response]): + 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 From 36b7d8515432b0c30dcc945478e396a3cc4ddc1c Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 3 May 2024 21:25:28 -0400 Subject: [PATCH 3/5] Update fastapi/applications.py --- fastapi/applications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index b71107eaa..360946120 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -4517,7 +4517,7 @@ class FastAPI(Starlette): import time from typing import Awaitable, Callabe - from fastapi import FastAPI, Request + from fastapi import FastAPI, Request, Response app = FastAPI() From adcb567307d695ea95a84bb856b2a1edf3e56cfe Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 3 May 2024 21:30:10 -0400 Subject: [PATCH 4/5] Update fastapi/applications.py --- fastapi/applications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index 360946120..f8a07aaf7 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -4515,7 +4515,7 @@ class FastAPI(Starlette): ```python import time - from typing import Awaitable, Callabe + from typing import Awaitable, Callable from fastapi import FastAPI, Request, Response From 83375dcdbee97af93a7cf9f20a1ef5b476c7015c Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 3 May 2024 21:41:49 -0400 Subject: [PATCH 5/5] Apply suggestions from code review --- fastapi/applications.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index f8a07aaf7..26074a78a 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -4524,9 +4524,8 @@ class FastAPI(Starlette): @app.middleware("http") async def add_process_time_header( - request: Request, - call_next: Callable[[Request], Awaitable[Response] - ) -> Response: + request: Request, call_next: Callable[[Request], Awaitable[Response]] + ) -> Response: start_time = time.time() response = await call_next(request) process_time = time.time() - start_time