Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions openhands/app_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Comment on lines +102 to 104


Expand Down
37 changes: 37 additions & 0 deletions tests/unit/app_server/test_get_default_web_url.py
Original file line number Diff line number Diff line change
@@ -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'

Comment on lines +23 to +26
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'