From fa1bed184948381007f763bae1803c17e692916b Mon Sep 17 00:00:00 2001 From: Space Date: Wed, 2 Jul 2025 11:45:45 +0200 Subject: [PATCH] Skip processing request body for HTTP HEAD requests (#147899) * Skip processing request body for HTTP HEAD requests * Use aiohttp's must_be_empty_body() to check whether ingress requests should be streamed * Only call must_be_empty_body() once per request * Fix incorrect use of walrus operator --- homeassistant/components/hassio/ingress.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hassio/ingress.py b/homeassistant/components/hassio/ingress.py index e673c3a70e9..ca6764cfa34 100644 --- a/homeassistant/components/hassio/ingress.py +++ b/homeassistant/components/hassio/ingress.py @@ -11,6 +11,7 @@ from urllib.parse import quote import aiohttp from aiohttp import ClientTimeout, ClientWebSocketResponse, hdrs, web +from aiohttp.helpers import must_be_empty_body from aiohttp.web_exceptions import HTTPBadGateway, HTTPBadRequest from multidict import CIMultiDict from yarl import URL @@ -184,13 +185,16 @@ class HassIOIngress(HomeAssistantView): content_type = "application/octet-stream" # Simple request - if result.status in (204, 304) or ( + if (empty_body := must_be_empty_body(result.method, result.status)) or ( content_length is not UNDEFINED and (content_length_int := int(content_length)) <= MAX_SIMPLE_RESPONSE_SIZE ): # Return Response - body = await result.read() + if empty_body: + body = None + else: + body = await result.read() simple_response = web.Response( headers=headers, status=result.status,