From 1f07a4eba0071d9b7fc82b8ba660a524d92a6c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 15 Oct 2020 11:01:37 +0200 Subject: [PATCH] Forward client headers for proxied stream responses (#41663) --- homeassistant/components/hassio/http.py | 2 +- tests/components/hassio/test_http.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index e42a7378b3c..2c1445dd456 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -111,7 +111,7 @@ class HassIOView(HomeAssistantView): ) # Stream response - response = web.StreamResponse(status=client.status) + response = web.StreamResponse(status=client.status, headers=client.headers) response.content_type = client.content_type await response.prepare(request) diff --git a/tests/components/hassio/test_http.py b/tests/components/hassio/test_http.py index d069b311ab2..ea087cdc620 100644 --- a/tests/components/hassio/test_http.py +++ b/tests/components/hassio/test_http.py @@ -151,6 +151,27 @@ async def test_snapshot_upload_headers(hassio_client, aioclient_mock): req_headers["Content-Type"] == content_type +async def test_snapshot_download_headers(hassio_client, aioclient_mock): + """Test that we forward the full header for snapshot download.""" + content_disposition = "attachment; filename=test.tar" + aioclient_mock.get( + "http://127.0.0.1/snapshots/slug/download", + headers={ + "Content-Length": "50000000", + "Content-Disposition": content_disposition, + }, + ) + + resp = await hassio_client.get("/api/hassio/snapshots/slug/download") + + # Check we got right response + assert resp.status == 200 + + assert len(aioclient_mock.mock_calls) == 1 + + resp.headers["Content-Disposition"] == content_disposition + + def test_need_auth(hass): """Test if the requested path needs authentication.""" assert not _need_auth(hass, "addons/test/logo")