Skip to content

Commit

Permalink
fix: Safe Handling of "more_body" in ASGI Responses (#3845)
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrehancavdar authored Oct 30, 2024
1 parent da4cc0b commit ed35b61
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion litestar/middleware/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion litestar/middleware/response_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ed35b61

Please sign in to comment.