Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mangum/protocols/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ async def send(self, message: Message) -> None:
Awaited by the application to send ASGI `http` events.
"""
message_type = message["type"]
self.logger.info(
"%s: '%s' event received from application.", self.state, message_type
)

if (
self.state is HTTPCycleState.REQUEST
Expand Down Expand Up @@ -141,6 +138,12 @@ async def send(self, message: Message) -> None:
self.state = HTTPCycleState.COMPLETE
await self.app_queue.put({"type": "http.disconnect"})

self.logger.info(
Comment thread
aminalaee marked this conversation as resolved.
"%s %s %s",
self.request.method,
self.request.path,
self.response.status,
)
else:
raise UnexpectedMessage(
f"{self.state}: Unexpected '{message_type}' event received."
Expand Down
30 changes: 30 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,33 @@ async def app(scope, receive, send):
"vary": "Accept-Encoding",
}
assert response["body"] == base64.b64encode(brotli.compress(body.encode())).decode()


@pytest.mark.parametrize(
"mock_aws_api_gateway_event", [["GET", b"", None]], indirect=True
)
def test_http_logging(mock_aws_api_gateway_event, caplog) -> None:
async def app(scope, receive, send):
assert scope["type"] == "http"
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain; charset=utf-8"]],
}
)

await send({"type": "http.response.body", "body": b"Hello, world!"})

handler = Mangum(app, lifespan="off")
response = handler(mock_aws_api_gateway_event, {})

assert response == {
"statusCode": 200,
"isBase64Encoded": False,
"headers": {"content-type": "text/plain; charset=utf-8"},
"multiValueHeaders": {},
"body": "Hello, world!",
}

assert "GET /test/hello 200" in caplog.text