Merge pull request #11957 from domdent/docs/edit-timer-in-middleware

📝 Tweak middleware code sample `time.time()` to `time.perf_counter()`
This commit is contained in:
Esteban Maya 2024-08-30 22:22:52 -05:00 committed by GitHub
commit 1b5984b23b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -7,8 +7,8 @@ app = FastAPI()
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
start_time = time.perf_counter()
response = await call_next(request)
process_time = time.time() - start_time
process_time = time.perf_counter() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response