MCPcopy Create free account
hub / github.com/aio-libs/aiohttp / __call__

Method __call__

examples/logging_middleware.py:30–56  ·  view source on GitHub ↗
(
        self,
        request: ClientRequest,
        handler: ClientHandlerType,
    )

Source from the content-addressed store, hash-verified

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
59class TestServer:

Callers

nothing calls this directly

Calls 2

debugMethod · 0.80
handlerFunction · 0.70

Tested by

no test coverage detected