1515 pass
1616
1717from errno import EAGAIN , ECONNRESET , ETIMEDOUT
18+ from time import monotonic
1819from traceback import print_exception
1920
2021from .authentication import Basic , Token , Bearer , require_authentication
@@ -358,6 +359,8 @@ def poll(self) -> str:
358359 conn , client_address = self ._sock .accept ()
359360 conn .settimeout (self ._timeout )
360361
362+ _debug_start_time = monotonic ()
363+
361364 # Receive the whole request
362365 if (request := self ._receive_request (conn , client_address )) is None :
363366 conn .close ()
@@ -378,8 +381,10 @@ def poll(self) -> str:
378381 # Send the response
379382 response ._send () # pylint: disable=protected-access
380383
384+ _debug_end_time = monotonic ()
385+
381386 if self .debug :
382- _debug_response_sent (response )
387+ _debug_response_sent (response , _debug_end_time - _debug_start_time )
383388
384389 return REQUEST_HANDLED_RESPONSE_SENT
385390
@@ -496,7 +501,7 @@ def _debug_started_server(server: "Server"):
496501 print (f"Started development server on http://{ host } :{ port } " )
497502
498503
499- def _debug_response_sent (response : "Response" ):
504+ def _debug_response_sent (response : "Response" , time_elapsed : float ):
500505 """Prints a message when after a response is sent."""
501506 # pylint: disable=protected-access
502507 client_ip = response ._request .client_address [0 ]
@@ -505,8 +510,11 @@ def _debug_response_sent(response: "Response"):
505510 req_size = len (response ._request .raw_request )
506511 status = response ._status
507512 res_size = response ._size
513+ time_elapsed_ms = f"{ round (time_elapsed * 1000 )} ms"
508514
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+ )
510518
511519
512520def _debug_stopped_server (server : "Server" ): # pylint: disable=unused-argument
0 commit comments