Skip to content

Commit 5177b98

Browse files
authored
Fixed TUI web socket and client version check URL construction logic (#557)
* Added logic to account for proxy paths if request was passed through a frontend * Added logic to client version checking functions to resolve proxy paths
1 parent 03a2b40 commit 5177b98

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/murfey/client/update.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ def check(api_base: ParseResult, install: bool = True, force: bool = False):
1515
If the version number is outside the allowed range then this can trigger
1616
an update on the client, and in that case will terminate the process.
1717
"""
18+
proxy_path = api_base.path.rstrip("/")
1819
version_check_url = api_base._replace(
19-
path="/version", query=f"client_version={murfey.__version__}"
20+
path=f"{proxy_path}/version/", query=f"client_version={murfey.__version__}"
2021
)
2122
server_reply = requests.get(version_check_url.geturl())
2223
if server_reply.status_code != 200:
@@ -59,6 +60,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool:
5960
Return 'true' on success and 'false' on error."""
6061

6162
assert api_base.hostname is not None
63+
proxy_path = api_base.path.rstrip("/")
6264
result = subprocess.run(
6365
[
6466
sys.executable,
@@ -67,7 +69,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool:
6769
"--trusted-host",
6870
api_base.hostname,
6971
"-i",
70-
api_base._replace(path="/pypi", query="").geturl(),
72+
api_base._replace(path=f"{proxy_path}/pypi", query="").geturl(),
7173
f"murfey[client]=={version}",
7274
]
7375
)

src/murfey/client/websocket.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,24 @@ def __init__(
2525
self.id = uuid.uuid4() if id is None else id
2626
log.info(f"Opening websocket connection for Client {self.id}")
2727
websocket.enableTrace(True)
28-
url = urllib.parse.urlparse(server)._replace(scheme="ws", path="")
28+
29+
# Parse server URL and get proxy path used, if any
30+
url = urllib.parse.urlparse(server)._replace(scheme="ws")
31+
proxy_path = url.path.rstrip("/")
32+
2933
self._address = url.geturl()
3034
self._alive = True
3135
self._ready = False
3236
self._send_queue: queue.Queue[Optional[str]] = queue.Queue()
3337
self._receive_queue: queue.Queue[Optional[str]] = queue.Queue()
38+
39+
# Construct the websocket URL
40+
# Prepend the proxy path to the new URL path
41+
# It will evaluate to "" if nothing's there, and starts with "/" if present
3442
ws_url = (
35-
url._replace(path=f"/ws/test/{self.id}").geturl()
43+
url._replace(path=f"{proxy_path}/ws/test/{self.id}").geturl()
3644
if register_client
37-
else url._replace(path=f"/ws/connect/{self.id}").geturl()
45+
else url._replace(path=f"{proxy_path}/ws/connect/{self.id}").geturl()
3846
)
3947
self._ws = websocket.WebSocketApp(
4048
ws_url,

0 commit comments

Comments
 (0)