feat(gateway): add URL normalization for websocket schemes in gateway configuration
This commit is contained in:
parent
a58bbe9f99
commit
5389a5cf9b
|
|
@ -180,11 +180,22 @@ class GatewayConfig:
|
||||||
disable_device_pairing: bool = False
|
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:
|
def _build_gateway_url(config: GatewayConfig) -> str:
|
||||||
base_url: str = (config.url or "").strip()
|
base_url: str = (config.url or "").strip()
|
||||||
if not base_url:
|
if not base_url:
|
||||||
message = "Gateway URL is not configured."
|
message = "Gateway URL is not configured."
|
||||||
raise OpenClawGatewayError(message)
|
raise OpenClawGatewayError(message)
|
||||||
|
base_url = _normalise_gateway_scheme(base_url)
|
||||||
token = config.token
|
token = config.token
|
||||||
if not token:
|
if not token:
|
||||||
return base_url
|
return base_url
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue