FastAPI - Middleware and Hooks
Identify the error in this FastAPI request timing middleware code:
import time
from fastapi import FastAPI
app = FastAPI()
@app.middleware('http')
def timing_middleware(request, call_next):
start = time.time()
response = call_next(request)
duration = time.time() - start
response.headers['X-Time'] = str(duration)
return response