diff --git a/supervisor/api/host.py b/supervisor/api/host.py index cc657e3e0..bc43aa6e3 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -240,7 +240,9 @@ class APIHost(CoreSysAttributes): f"Cannot determine CONTAINER_LOG_EPOCH of {identifier}, latest logs not available." ) from err - if ACCEPT in request.headers and request.headers[ACCEPT] not in [ + accept_header = request.headers.get(ACCEPT) + + if accept_header and accept_header not in [ CONTENT_TYPE_TEXT, CONTENT_TYPE_X_LOG, "*/*", @@ -250,7 +252,7 @@ class APIHost(CoreSysAttributes): "supported for now." ) - if "verbose" in request.query or request.headers[ACCEPT] == CONTENT_TYPE_X_LOG: + if "verbose" in request.query or accept_header == CONTENT_TYPE_X_LOG: log_formatter = LogFormatter.VERBOSE if "no_colors" in request.query: diff --git a/tests/api/test_host.py b/tests/api/test_host.py index a3a38b5e2..7c933cd63 100644 --- a/tests/api/test_host.py +++ b/tests/api/test_host.py @@ -374,6 +374,11 @@ async def test_advanced_logs_formatters( await api_client.get("/host/logs/identifiers/test", headers=headers) journal_logs_reader.assert_called_once_with(ANY, LogFormatter.VERBOSE, False) + journal_logs_reader.reset_mock() + + await api_client.get("/host/logs/identifiers/test", skip_auto_headers={"Accept"}) + journal_logs_reader.assert_called_once_with(ANY, LogFormatter.PLAIN, False) + async def test_advanced_logs_errors(coresys: CoreSys, api_client: TestClient): """Test advanced logging API errors."""