import fastapi
import fastapi.middleware.cors
+import time
from .. import Backend
debug = True,
)
+@app.middleware("http")
+async def add_process_time_header(request: fastapi.Request, call_next):
+ """
+ Add the processing time of the request to the response headers.
+ """
+ # Store the start time
+ t_start = time.perf_counter()
+
+ # Continue to run the request...
+ response = await call_next(request)
+
+ # Store the end time
+ t_end = time.perf_counter()
+
+ # Set the process time in the header in milliseconds
+ response.headers["X-Process-Time"] = "%.2fms" % ((t_end - t_start) * 1000.0)
+
+ return response
+
# Add CORS
app.add_middleware(
fastapi.middleware.cors.CORSMiddleware,