From e23c1fcc97f5f7fa2106805123b543db8b570100 Mon Sep 17 00:00:00 2001 From: nggit Date: Sun, 16 Mar 2025 08:43:20 +0700 Subject: [PATCH 1/2] allow custom status on exit instead of 500 --- httpout/response.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/httpout/response.py b/httpout/response.py index 6edcdb2..32590bf 100644 --- a/httpout/response.py +++ b/httpout/response.py @@ -42,12 +42,12 @@ async def handle_exception(self, exc): if self.response.request.upgraded: await self.response.handle_exception(exc) else: - if not self.response.headers_sent(): - self.response.set_status(500, b'Internal Server Error') - self.response.set_content_type(b'text/html; charset=utf-8') - self.response.request.http_keepalive = False - if isinstance(exc, Exception): + if not self.response.headers_sent(): + self.response.set_status(500, b'Internal Server Error') + self.response.set_content_type(b'text/html; charset=utf-8') + self.response.request.http_keepalive = False + if self.protocol.options['debug']: te = TracebackException.from_exception(exc) await self.response.write( From bc78e44a5c00bcd282777aa8e4b3b9faa48fb68a Mon Sep 17 00:00:00 2001 From: nggit Date: Mon, 17 Mar 2025 08:13:55 +0700 Subject: [PATCH 2/2] close on all exc --- httpout/response.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/httpout/response.py b/httpout/response.py index 32590bf..381b1e7 100644 --- a/httpout/response.py +++ b/httpout/response.py @@ -42,11 +42,12 @@ async def handle_exception(self, exc): if self.response.request.upgraded: await self.response.handle_exception(exc) else: + self.response.request.http_keepalive = False + if isinstance(exc, Exception): if not self.response.headers_sent(): self.response.set_status(500, b'Internal Server Error') self.response.set_content_type(b'text/html; charset=utf-8') - self.response.request.http_keepalive = False if self.protocol.options['debug']: te = TracebackException.from_exception(exc)