diff --git a/openhands/app_server/config.py b/openhands/app_server/config.py index 0b674ab..cdfd543 100644 --- a/openhands/app_server/config.py +++ b/openhands/app_server/config.py @@ -92,11 +92,15 @@ def get_default_persistence_dir() -> Path: def get_default_web_url() -> str | None: """Get legacy web host parameter. - If present, we assume we are running under https. + Bare hosts keep the historical ``https://`` default (cloud). Values that + already include a scheme are passed through so self-hosted HTTP + deployments can set ``WEB_HOST=http://host.docker.internal:3000``. """ - web_host = os.getenv('WEB_HOST') + web_host = (os.getenv('WEB_HOST') or '').strip() if not web_host: return None + if '://' in web_host: + return web_host.rstrip('/') return f'https://{web_host}' diff --git a/tests/unit/app_server/test_get_default_web_url.py b/tests/unit/app_server/test_get_default_web_url.py new file mode 100644 index 0000000..13adb60 --- /dev/null +++ b/tests/unit/app_server/test_get_default_web_url.py @@ -0,0 +1,37 @@ +"""Tests for get_default_web_url WEB_HOST scheme handling.""" + +from openhands.app_server.config import get_default_web_url + + +class TestGetDefaultWebUrl: + def test_unset(self, monkeypatch): + monkeypatch.delenv('WEB_HOST', raising=False) + assert get_default_web_url() is None + + def test_empty(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', '') + assert get_default_web_url() is None + + def test_whitespace(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', ' ') + assert get_default_web_url() is None + + def test_bare_host_keeps_https_default(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', 'app.all-hands.dev') + assert get_default_web_url() == 'https://app.all-hands.dev' + + def test_bare_host_with_port(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', 'host.docker.internal:3000') + assert get_default_web_url() == 'https://host.docker.internal:3000' + + def test_explicit_http_scheme_is_preserved(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', 'http://host.docker.internal:3000') + assert get_default_web_url() == 'http://host.docker.internal:3000' + + def test_explicit_https_scheme_is_preserved(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', 'https://app.all-hands.dev') + assert get_default_web_url() == 'https://app.all-hands.dev' + + def test_trailing_slash_stripped_when_scheme_present(self, monkeypatch): + monkeypatch.setenv('WEB_HOST', 'http://localhost:3000/') + assert get_default_web_url() == 'http://localhost:3000'