Skip to content

Commit 00dfc04

Browse files
authored
Skip processing request body for HTTP HEAD requests (home-assistant#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
1 parent bee07ad commit 00dfc04

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

homeassistant/components/hassio/ingress.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import aiohttp
1313
from aiohttp import ClientTimeout, ClientWebSocketResponse, hdrs, web
14+
from aiohttp.helpers import must_be_empty_body
1415
from aiohttp.web_exceptions import HTTPBadGateway, HTTPBadRequest
1516
from multidict import CIMultiDict
1617
from yarl import URL
@@ -184,13 +185,16 @@ async def _handle_request(
184185
content_type = "application/octet-stream"
185186

186187
# Simple request
187-
if result.status in (204, 304) or (
188+
if (empty_body := must_be_empty_body(result.method, result.status)) or (
188189
content_length is not UNDEFINED
189190
and (content_length_int := int(content_length))
190191
<= MAX_SIMPLE_RESPONSE_SIZE
191192
):
192193
# Return Response
193-
body = await result.read()
194+
if empty_body:
195+
body = None
196+
else:
197+
body = await result.read()
194198
simple_response = web.Response(
195199
headers=headers,
196200
status=result.status,

0 commit comments

Comments
 (0)