Skip to content

fix: preserve WEB_HOST scheme in get_default_web_url - #7

Open
xiehuanyi wants to merge 1 commit into
OpenHands:mainfrom
xiehuanyi:fix/web-host-scheme
Open

fix: preserve WEB_HOST scheme in get_default_web_url#7
xiehuanyi wants to merge 1 commit into
OpenHands:mainfrom
xiehuanyi:fix/web-host-scheme

Conversation

@xiehuanyi

Copy link
Copy Markdown

Summary

get_default_web_url() always prefixed https://. That made self-hosted / rootless Podman setups unable to point internal MCP/webhook callbacks at a plain HTTP app server:

  • WEB_HOST=host.docker.internal:3000 -> https://host.docker.internal:3000 (TLS against HTTP)
  • WEB_HOST=http://host.docker.internal:3000 -> https://http://host.docker.internal:3000

Bare hosts still get https:// so cloud is unchanged. If the value already has a scheme, it is passed through.

Related: OpenHands/software-agent-sdk#4493 (maintainer asked for this scheme fix). The default 405 with no WEB_HOST is a separate host/port issue (OH_SANDBOX_HOST_PORT / fallback http://host.docker.internal:{host_port}). Conversation hard-fail on MCP connect is OpenHands/software-agent-sdk#4462.

Test plan

  • Unit tests for unset / empty / bare host / explicit http:// / explicit https://
  • CI tests/unit/app_server/test_get_default_web_url.py

Made with Cursor

Bare hosts still get https://. An explicit http:// or https:// value is
kept so self-hosted / Podman setups can point internal MCP callbacks at
plain HTTP without a TLS handshake against a non-TLS port.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates get_default_web_url() in openhands/app_server/config.py to preserve an explicitly provided URL scheme in WEB_HOST, while keeping the historical https:// default for bare hosts—supporting self-hosted HTTP deployments without breaking cloud defaults.

Changes:

  • Normalize WEB_HOST by stripping whitespace and returning None when unset/blank.
  • Preserve explicitly schemed WEB_HOST values (e.g. http://...) instead of always forcing https://.
  • Add unit tests covering unset/empty/whitespace, bare hosts, and explicit http:// / https:// handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
openhands/app_server/config.py Preserves an explicit scheme in WEB_HOST and keeps https:// default for bare hosts.
tests/unit/app_server/test_get_default_web_url.py Adds unit tests for scheme-preservation and empty/unset handling of WEB_HOST.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +102 to 104
if '://' in web_host:
return web_host.rstrip('/')
return f'https://{web_host}'
Comment on lines +23 to +26
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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants