mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Small performance improvements to ingress forwarding (#116457)
This commit is contained in:
parent
1e63665bf2
commit
ff104f54b5
@ -177,11 +177,13 @@ class HassIOIngress(HomeAssistantView):
|
||||
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"
|
||||
|
||||
# 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))
|
||||
<= MAX_SIMPLE_RESPONSE_SIZE
|
||||
):
|
||||
# Return Response
|
||||
@ -194,17 +196,17 @@ class HassIOIngress(HomeAssistantView):
|
||||
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):
|
||||
response.enable_compression()
|
||||
await response.prepare(request)
|
||||
# In testing iter_chunked, iter_any, and iter_chunks:
|
||||
|
Loading…
x
Reference in New Issue
Block a user