From ac9050115b216f43a119724d3c80ce116235020d Mon Sep 17 00:00:00 2001 From: cemrehancavdar <50503448+cemrehancavdar@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:41:43 +0300 Subject: [PATCH 1/3] fix: safe access to more_body on message --- litestar/middleware/logging.py | 2 +- litestar/middleware/response_cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/litestar/middleware/logging.py b/litestar/middleware/logging.py index b589b13c72..3eb6baf085 100644 --- a/litestar/middleware/logging.py +++ b/litestar/middleware/logging.py @@ -227,7 +227,7 @@ async def send_wrapper(message: Message) -> None: connection_state.log_context[HTTP_RESPONSE_BODY] = message self.log_response(scope=scope) - if not message["more_body"]: + if not message.get('more_body'): connection_state.log_context.clear() await send(message) diff --git a/litestar/middleware/response_cache.py b/litestar/middleware/response_cache.py index 62dcde6e23..8d63d94587 100644 --- a/litestar/middleware/response_cache.py +++ b/litestar/middleware/response_cache.py @@ -49,7 +49,7 @@ async def wrapped_send(message: Message) -> None: elif value_or_default(connection_state.do_cache, False): messages.append(message) - if messages and message["type"] == HTTP_RESPONSE_BODY and not message["more_body"]: + if messages and message["type"] == HTTP_RESPONSE_BODY and not message.get('more_body') key = (route_handler.cache_key_builder or self.config.key_builder)(Request(scope)) store = self.config.get_store_from_app(scope["app"]) await store.set(key, encode_msgpack(messages), expires_in=expires_in) From 85592396b132da451f2c79d8c0c8e24a78eedaa8 Mon Sep 17 00:00:00 2001 From: cemrehancavdar <50503448+cemrehancavdar@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:56:21 +0300 Subject: [PATCH 2/3] fix: missing colon --- litestar/middleware/response_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litestar/middleware/response_cache.py b/litestar/middleware/response_cache.py index 8d63d94587..fb9fe71462 100644 --- a/litestar/middleware/response_cache.py +++ b/litestar/middleware/response_cache.py @@ -49,7 +49,7 @@ async def wrapped_send(message: Message) -> None: elif value_or_default(connection_state.do_cache, False): messages.append(message) - if messages and message["type"] == HTTP_RESPONSE_BODY and not message.get('more_body') + if messages and message["type"] == HTTP_RESPONSE_BODY and not message.get('more_body'): key = (route_handler.cache_key_builder or self.config.key_builder)(Request(scope)) store = self.config.get_store_from_app(scope["app"]) await store.set(key, encode_msgpack(messages), expires_in=expires_in) From 24ef67a32508a403bbd12c5488f50ca9a30af331 Mon Sep 17 00:00:00 2001 From: cemrehancavdar <50503448+cemrehancavdar@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:09:31 +0000 Subject: [PATCH 3/3] fix: to double quote --- litestar/middleware/logging.py | 2 +- litestar/middleware/response_cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/litestar/middleware/logging.py b/litestar/middleware/logging.py index 3eb6baf085..c909dfed23 100644 --- a/litestar/middleware/logging.py +++ b/litestar/middleware/logging.py @@ -227,7 +227,7 @@ async def send_wrapper(message: Message) -> None: connection_state.log_context[HTTP_RESPONSE_BODY] = message self.log_response(scope=scope) - if not message.get('more_body'): + if not message.get("more_body"): connection_state.log_context.clear() await send(message) diff --git a/litestar/middleware/response_cache.py b/litestar/middleware/response_cache.py index fb9fe71462..a2c4bf7e71 100644 --- a/litestar/middleware/response_cache.py +++ b/litestar/middleware/response_cache.py @@ -49,7 +49,7 @@ async def wrapped_send(message: Message) -> None: elif value_or_default(connection_state.do_cache, False): messages.append(message) - if messages and message["type"] == HTTP_RESPONSE_BODY and not message.get('more_body'): + if messages and message["type"] == HTTP_RESPONSE_BODY and not message.get("more_body"): key = (route_handler.cache_key_builder or self.config.key_builder)(Request(scope)) store = self.config.get_store_from_app(scope["app"]) await store.set(key, encode_msgpack(messages), expires_in=expires_in)