feat(gateway): add URL normalization for websocket schemes in gateway configuration

This commit is contained in:
null 2026-05-22 04:12:38 -05:00
parent a58bbe9f99
commit 5389a5cf9b
1 changed files with 11 additions and 0 deletions

View File

@ -180,11 +180,22 @@ class GatewayConfig:
disable_device_pairing: bool = False
def _normalise_gateway_scheme(url: str) -> str:
"""Convert http/https gateway URLs to the ws/wss scheme websockets expects."""
parsed = urlparse(url)
if parsed.scheme == "http":
return urlunparse(parsed._replace(scheme="ws"))
if parsed.scheme == "https":
return urlunparse(parsed._replace(scheme="wss"))
return url
def _build_gateway_url(config: GatewayConfig) -> str:
base_url: str = (config.url or "").strip()
if not base_url:
message = "Gateway URL is not configured."
raise OpenClawGatewayError(message)
base_url = _normalise_gateway_scheme(base_url)
token = config.token
if not token:
return base_url