diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index 6dccdeb2101..aba0dac6494 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -18,6 +18,7 @@ from .const import X_HASS_IS_ADMIN, X_HASS_USER_ID, X_HASSIO _LOGGER = logging.getLogger(__name__) +MAX_UPLOAD_SIZE = 1024 * 1024 * 1024 NO_TIMEOUT = re.compile( r"^(?:" @@ -71,6 +72,16 @@ class HassIOView(HomeAssistantView): read_timeout = _get_timeout(path) data = None headers = _init_header(request) + if path == "snapshots/new/upload": + # We need to reuse the full content type that includes the boundary + headers[ + "Content-Type" + ] = request._stored_content_type # pylint: disable=protected-access + + # Snapshots are big, so we need to adjust the allowed size + request._client_max_size = ( # pylint: disable=protected-access + MAX_UPLOAD_SIZE + ) try: with async_timeout.timeout(10): diff --git a/tests/components/hassio/test_http.py b/tests/components/hassio/test_http.py index 7386cf57d0c..195a8652e2f 100644 --- a/tests/components/hassio/test_http.py +++ b/tests/components/hassio/test_http.py @@ -129,3 +129,21 @@ async def test_forwarding_user_info(hassio_client, hass_admin_user, aioclient_mo req_headers = aioclient_mock.mock_calls[0][-1] req_headers["X-Hass-User-ID"] == hass_admin_user.id req_headers["X-Hass-Is-Admin"] == "1" + + +async def test_snapshot_upload_headers(hassio_client, aioclient_mock): + """Test that we forward the full header for snapshot upload.""" + content_type = "multipart/form-data; boundary='--webkit'" + aioclient_mock.get("http://127.0.0.1/snapshots/new/upload") + + resp = await hassio_client.get( + "/api/hassio/snapshots/new/upload", headers={"Content-Type": content_type} + ) + + # Check we got right response + assert resp.status == 200 + + assert len(aioclient_mock.mock_calls) == 1 + + req_headers = aioclient_mock.mock_calls[0][-1] + req_headers["Content-Type"] == content_type