fix: report sub-second timings in the X-Process-Time header (#27368)

The header value was truncated with int(), so every request faster than one second reported X-Process-Time: 0 and the header carried no information for exactly the requests it is meant to describe. Emit fractional seconds with microsecond precision instead, matching the pre-ASGI-refactor behavior where the raw float was sent.
This commit is contained in:
Classic298 2026-07-24 01:09:23 +02:00 committed by GitHub
parent e0918ddb40
commit 3d45947053
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -172,9 +172,9 @@ class AuthTokenMiddleware:
async def send_with_timing(message: Message) -> None:
if message['type'] == 'http.response.start':
process_time = int(time.monotonic() - start_time)
process_time = time.monotonic() - start_time
headers = MutableHeaders(scope=message)
headers['X-Process-Time'] = str(process_time)
headers['X-Process-Time'] = f'{process_time:.6f}'
await send(message)
await self.app(scope, receive, send_with_timing)