Forward client headers for proxied stream responses (#41663)

This commit is contained in:
Joakim Sørensen 2020-10-15 11:01:37 +02:00 committed by GitHub
parent 690024b34a
commit 1f07a4eba0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -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)

View file

@ -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")