| 28 | """Middleware that logs request timing and response status.""" |
| 29 | |
| 30 | async def __call__( |
| 31 | self, |
| 32 | request: ClientRequest, |
| 33 | handler: ClientHandlerType, |
| 34 | ) -> ClientResponse: |
| 35 | start_time = time.monotonic() |
| 36 | |
| 37 | # Log request |
| 38 | _LOGGER.info("[REQUEST] %s %s", request.method, request.url) |
| 39 | if request.headers: |
| 40 | _LOGGER.debug("[REQUEST HEADERS] %s", request.headers) |
| 41 | |
| 42 | # Execute request |
| 43 | response = await handler(request) |
| 44 | |
| 45 | # Log response |
| 46 | duration = time.monotonic() - start_time |
| 47 | _LOGGER.info( |
| 48 | "[RESPONSE] %s %s - Status: %s - Duration: %.3fs", |
| 49 | request.method, |
| 50 | request.url, |
| 51 | response.status, |
| 52 | duration, |
| 53 | ) |
| 54 | _LOGGER.debug("[RESPONSE HEADERS] %s", response.headers) |
| 55 | |
| 56 | return response |
| 57 | |
| 58 | |
| 59 | class TestServer: |