From 898ce9d30034456768914704147a9e94ef458a19 Mon Sep 17 00:00:00 2001 From: Tomi Belan Date: Sun, 24 May 2026 23:39:57 +0200 Subject: [PATCH] Fix duplicate access logs --- src/hypercorn/protocol/http_stream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hypercorn/protocol/http_stream.py b/src/hypercorn/protocol/http_stream.py index 206ad6d..83fa2c3 100644 --- a/src/hypercorn/protocol/http_stream.py +++ b/src/hypercorn/protocol/http_stream.py @@ -241,12 +241,13 @@ async def app_send(self, message: ASGISendEvent | None) -> None: raise UnexpectedMessageError(self.state, message["type"]) async def _send_closed(self) -> None: - await self.send(EndBody(stream_id=self.stream_id)) self.state = ASGIHTTPState.CLOSED + await self.send(EndBody(stream_id=self.stream_id)) await self.config.log.access(self.scope, self.response, time() - self.start_time) await self.send(StreamClosed(stream_id=self.stream_id)) async def _send_error_response(self, status_code: int) -> None: + self.state = ASGIHTTPState.CLOSED await self.send( Response( stream_id=self.stream_id, @@ -255,7 +256,6 @@ async def _send_error_response(self, status_code: int) -> None: ) ) await self.send(EndBody(stream_id=self.stream_id)) - self.state = ASGIHTTPState.CLOSED await self.config.log.access( self.scope, {"status": status_code, "headers": []}, time() - self.start_time )