From c95ddf4e87a3e7566103496155577f488dc2cc80 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Tue, 1 Apr 2025 16:45:55 +0100 Subject: [PATCH 1/4] Added logic to account for proxy paths if request was passed through a frontend --- src/murfey/client/websocket.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/murfey/client/websocket.py b/src/murfey/client/websocket.py index 956800218..fc843ecf3 100644 --- a/src/murfey/client/websocket.py +++ b/src/murfey/client/websocket.py @@ -25,16 +25,23 @@ def __init__( self.id = uuid.uuid4() if id is None else id log.info(f"Opening websocket connection for Client {self.id}") websocket.enableTrace(True) - url = urllib.parse.urlparse(server)._replace(scheme="ws", path="") + + url = urllib.parse.urlparse(server)._replace(scheme="ws") + proxy_path = url.path # Path component indicates what the proxy path used was + self._address = url.geturl() self._alive = True self._ready = False self._send_queue: queue.Queue[Optional[str]] = queue.Queue() self._receive_queue: queue.Queue[Optional[str]] = queue.Queue() + + # Construct the websocket URL + # Prepend the proxy path to the new URL path + # It will evaluate to "" if nothing's there, and starts with "/path" if present ws_url = ( - url._replace(path=f"/ws/test/{self.id}").geturl() + url._replace(path=f"{proxy_path}/ws/test/{self.id}").geturl() if register_client - else url._replace(path=f"/ws/connect/{self.id}").geturl() + else url._replace(path=f"{proxy_path}/ws/connect/{self.id}").geturl() ) self._ws = websocket.WebSocketApp( ws_url, From 0be1eb332fe87af357dd960e3393df36e041ce50 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Tue, 1 Apr 2025 17:46:24 +0100 Subject: [PATCH 2/4] Added logic to client version checking functions to resolve proxy paths --- src/murfey/client/update.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/murfey/client/update.py b/src/murfey/client/update.py index d000b430e..634b01268 100644 --- a/src/murfey/client/update.py +++ b/src/murfey/client/update.py @@ -15,8 +15,9 @@ def check(api_base: ParseResult, install: bool = True, force: bool = False): If the version number is outside the allowed range then this can trigger an update on the client, and in that case will terminate the process. """ + proxy_path = api_base.path version_check_url = api_base._replace( - path="/version", query=f"client_version={murfey.__version__}" + path=f"{proxy_path}/version", query=f"client_version={murfey.__version__}" ) server_reply = requests.get(version_check_url.geturl()) if server_reply.status_code != 200: @@ -59,6 +60,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool: Return 'true' on success and 'false' on error.""" assert api_base.hostname is not None + proxy_path = api_base.path result = subprocess.run( [ sys.executable, @@ -67,7 +69,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool: "--trusted-host", api_base.hostname, "-i", - api_base._replace(path="/pypi", query="").geturl(), + api_base._replace(path=f"{proxy_path}/pypi", query="").geturl(), f"murfey[client]=={version}", ] ) From 17e0c21ccaeb982e2cf18e615e61a9543c496f09 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 2 Apr 2025 11:01:28 +0100 Subject: [PATCH 3/4] Version check URL generated incorrectly; ensured no trailing '/' in proxy_path component --- src/murfey/client/update.py | 6 +++--- src/murfey/client/websocket.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/murfey/client/update.py b/src/murfey/client/update.py index 634b01268..49570bd1b 100644 --- a/src/murfey/client/update.py +++ b/src/murfey/client/update.py @@ -15,9 +15,9 @@ def check(api_base: ParseResult, install: bool = True, force: bool = False): If the version number is outside the allowed range then this can trigger an update on the client, and in that case will terminate the process. """ - proxy_path = api_base.path + proxy_path = api_base.path.rstrip("/") version_check_url = api_base._replace( - path=f"{proxy_path}/version", query=f"client_version={murfey.__version__}" + path=f"{proxy_path}/version/", query=f"client_version={murfey.__version__}" ) server_reply = requests.get(version_check_url.geturl()) if server_reply.status_code != 200: @@ -60,7 +60,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool: Return 'true' on success and 'false' on error.""" assert api_base.hostname is not None - proxy_path = api_base.path + proxy_path = api_base.path.rstrip("/") result = subprocess.run( [ sys.executable, diff --git a/src/murfey/client/websocket.py b/src/murfey/client/websocket.py index fc843ecf3..ea74cdbbd 100644 --- a/src/murfey/client/websocket.py +++ b/src/murfey/client/websocket.py @@ -27,7 +27,9 @@ def __init__( websocket.enableTrace(True) url = urllib.parse.urlparse(server)._replace(scheme="ws") - proxy_path = url.path # Path component indicates what the proxy path used was + proxy_path = url.path.rstrip( + "/" + ) # Path component indicates what the proxy path used was self._address = url.geturl() self._alive = True From 17ac97f14f38b0c383decc87f17187f71a331b5d Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 2 Apr 2025 11:15:45 +0100 Subject: [PATCH 4/4] Tidied up comments --- src/murfey/client/websocket.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/murfey/client/websocket.py b/src/murfey/client/websocket.py index ea74cdbbd..d693f14b9 100644 --- a/src/murfey/client/websocket.py +++ b/src/murfey/client/websocket.py @@ -26,10 +26,9 @@ def __init__( log.info(f"Opening websocket connection for Client {self.id}") websocket.enableTrace(True) + # Parse server URL and get proxy path used, if any url = urllib.parse.urlparse(server)._replace(scheme="ws") - proxy_path = url.path.rstrip( - "/" - ) # Path component indicates what the proxy path used was + proxy_path = url.path.rstrip("/") self._address = url.geturl() self._alive = True @@ -39,7 +38,7 @@ def __init__( # Construct the websocket URL # Prepend the proxy path to the new URL path - # It will evaluate to "" if nothing's there, and starts with "/path" if present + # It will evaluate to "" if nothing's there, and starts with "/" if present ws_url = ( url._replace(path=f"{proxy_path}/ws/test/{self.id}").geturl() if register_client