Skip to content

Commit 20bc40a

Browse files
committed
fix(client): preserve hub path prefix when building the ws url
_to_ws_url documented that it keeps the port and any path prefix, but it only kept u.netloc and appended the ws path, so a scheme'd url like https://hub.example.com/zhub lost the /zhub prefix. A hub reverse-proxied under a path was silently routed to the wrong /ws endpoint. Keep u.path as a prefix (stripping a trailing slash); the bare-host branch splits host from prefix the same way. Port handling is unchanged.
1 parent 3c9b342 commit 20bc40a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

zhub/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ def _to_ws_url(http_or_ws_url: str, ws_path: str) -> str:
4848
Accepts already-ws URLs. Preserves port + path prefix."""
4949
u = urlparse(http_or_ws_url)
5050
scheme = {"https": "wss", "http": "ws", "wss": "wss", "ws": "ws"}.get(u.scheme, "wss")
51-
netloc = u.netloc or u.path # in case user passed bare host
51+
netloc = u.netloc
52+
prefix = u.path
53+
if not netloc:
54+
# No scheme given — urlparse puts the whole "host[/prefix]" in u.path.
55+
host, _, rest = u.path.partition("/")
56+
netloc = host
57+
prefix = f"/{rest}" if rest else ""
5258
if not netloc:
5359
raise ValueError(f"could not parse hub url: {http_or_ws_url}")
54-
return f"{scheme}://{netloc}{ws_path}"
60+
prefix = prefix.rstrip("/")
61+
return f"{scheme}://{netloc}{prefix}{ws_path}"
5562

5663

5764
# ---- publish mode --------------------------------------------------------

0 commit comments

Comments
 (0)