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

Small performance improvements to ingress forwarding #116457

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ async def _handle_request(
if maybe_content_type := result.headers.get(hdrs.CONTENT_TYPE):
content_type: str = (maybe_content_type.partition(";"))[0].strip()
else:
content_type = result.content_type
# default value according to RFC 2616
content_type = "application/octet-stream"
Comment on lines +180 to +181
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its missing aiohttp jumps through some hoops to get here


# Simple request
if result.status in (204, 304) or (
content_length is not UNDEFINED
and (content_length_int := int(content_length or 0))
and (content_length_int := int(content_length))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already checked for UNDEFINED

<= MAX_SIMPLE_RESPONSE_SIZE
):
# Return Response
Expand All @@ -194,17 +196,17 @@ async def _handle_request(
zlib_executor_size=32768,
)
if content_length_int > MIN_COMPRESSED_SIZE and should_compress(
content_type or simple_response.content_type
content_type
):
simple_response.enable_compression()
return simple_response

# Stream response
response = web.StreamResponse(status=result.status, headers=headers)
response.content_type = result.content_type
response.content_type = content_type

try:
if should_compress(response.content_type):
if should_compress(content_type):
Comment on lines -197 to +209
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid re-parsing it all over again since we already have it

response.enable_compression()
await response.prepare(request)
# In testing iter_chunked, iter_any, and iter_chunks:
Expand Down