Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Safe Handling of "more_body" in ASGI Responses #3845

Merged
merged 4 commits into from
Oct 30, 2024
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
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
Loading