Gabriel 1 week ago
committed by GitHub
parent
commit
60eb93a54e
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 ```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

Loading…
Cancel
Save