Fix ingress sending an empty body for GET requests (#101917)

This commit is contained in:
J. Nick Koston 2023-10-15 11:38:20 -10:00 committed by GitHub
parent 11740d1e68
commit 36e1c740fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -164,7 +164,7 @@ class HassIOView(HomeAssistantView):
method=request.method,
url=f"http://{self._host}/{quote(path)}",
params=request.query,
data=request.content,
data=request.content if request.method != "GET" else None,
headers=headers,
timeout=_get_timeout(path),
)

View File

@ -162,7 +162,7 @@ class HassIOIngress(HomeAssistantView):
headers=source_header,
params=request.query,
allow_redirects=False,
data=request.content,
data=request.content if request.method != "GET" else None,
timeout=ClientTimeout(total=None),
skip_auto_headers={hdrs.CONTENT_TYPE},
) as result:

View File

@ -450,11 +450,26 @@ async def test_backup_download_headers(
async def test_stream(hassio_client, aioclient_mock: AiohttpClientMocker) -> None:
"""Verify that the request is a stream."""
aioclient_mock.get("http://127.0.0.1/app/entrypoint.js")
await hassio_client.get("/api/hassio/app/entrypoint.js", data="test")
content_type = "multipart/form-data; boundary='--webkit'"
aioclient_mock.post("http://127.0.0.1/backups/new/upload")
resp = await hassio_client.post(
"/api/hassio/backups/new/upload", headers={"Content-Type": content_type}
)
# Check we got right response
assert resp.status == HTTPStatus.OK
assert isinstance(aioclient_mock.mock_calls[-1][2], StreamReader)
async def test_simple_get_no_stream(
hassio_client, aioclient_mock: AiohttpClientMocker
) -> None:
"""Verify that a simple GET request is not a stream."""
aioclient_mock.get("http://127.0.0.1/app/entrypoint.js")
resp = await hassio_client.get("/api/hassio/app/entrypoint.js")
assert resp.status == HTTPStatus.OK
assert aioclient_mock.mock_calls[-1][2] is None
async def test_entrypoint_cache_control(
hassio_client, aioclient_mock: AiohttpClientMocker
) -> None: