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:
1 parent
e0918ddb40
commit
3d45947053
1 file changed
+2
-2
@@ -172,9 +172,9 @@ class AuthTokenMiddleware:
|
|||||||
|
|
||||||
async def send_with_timing(message: Message) -> None:
|
async def send_with_timing(message: Message) -> None:
|
||||||
if message['type'] == 'http.response.start':
|
if message['type'] == 'http.response.start':
|
||||||
process_time = int(time.monotonic() - start_time)
|
process_time = time.monotonic() - start_time
|
||||||
headers = MutableHeaders(scope=message)
|
headers = MutableHeaders(scope=message)
|
||||||
headers['X-Process-Time'] = str(process_time)
|
headers['X-Process-Time'] = f'{process_time:.6f}'
|
||||||
await send(message)
|
await send(message)
|
||||||
|
|
||||||
await self.app(scope, receive, send_with_timing)
|
await self.app(scope, receive, send_with_timing)
|
||||||
|
|||||||
Reference in new issue
Block a user