15
15
pass
16
16
17
17
from errno import EAGAIN , ECONNRESET , ETIMEDOUT
18
+ from time import monotonic
18
19
from traceback import print_exception
19
20
20
21
from .authentication import Basic , Token , Bearer , require_authentication
@@ -358,6 +359,8 @@ def poll(self) -> str:
358
359
conn , client_address = self ._sock .accept ()
359
360
conn .settimeout (self ._timeout )
360
361
362
+ _debug_start_time = monotonic ()
363
+
361
364
# Receive the whole request
362
365
if (request := self ._receive_request (conn , client_address )) is None :
363
366
conn .close ()
@@ -378,8 +381,10 @@ def poll(self) -> str:
378
381
# Send the response
379
382
response ._send () # pylint: disable=protected-access
380
383
384
+ _debug_end_time = monotonic ()
385
+
381
386
if self .debug :
382
- _debug_response_sent (response )
387
+ _debug_response_sent (response , _debug_end_time - _debug_start_time )
383
388
384
389
return REQUEST_HANDLED_RESPONSE_SENT
385
390
@@ -496,7 +501,7 @@ def _debug_started_server(server: "Server"):
496
501
print (f"Started development server on http://{ host } :{ port } " )
497
502
498
503
499
- def _debug_response_sent (response : "Response" ):
504
+ def _debug_response_sent (response : "Response" , time_elapsed : float ):
500
505
"""Prints a message when after a response is sent."""
501
506
# pylint: disable=protected-access
502
507
client_ip = response ._request .client_address [0 ]
@@ -505,8 +510,11 @@ def _debug_response_sent(response: "Response"):
505
510
req_size = len (response ._request .raw_request )
506
511
status = response ._status
507
512
res_size = response ._size
513
+ time_elapsed_ms = f"{ round (time_elapsed * 1000 )} ms"
508
514
509
- print (f'{ client_ip } -- "{ method } { path } " { req_size } -- "{ status } " { res_size } ' )
515
+ print (
516
+ f'{ client_ip } -- "{ method } { path } " { req_size } -- "{ status } " { res_size } -- { time_elapsed_ms } '
517
+ )
510
518
511
519
512
520
def _debug_stopped_server (server : "Server" ): # pylint: disable=unused-argument
0 commit comments