Skip to content

Commit c95ddf4

Browse files
committed
Added logic to account for proxy paths if request was passed through a frontend
1 parent 03a2b40 commit c95ddf4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/murfey/client/websocket.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ 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+
url = urllib.parse.urlparse(server)._replace(scheme="ws")
30+
proxy_path = url.path # Path component indicates what the proxy path used was
31+
2932
self._address = url.geturl()
3033
self._alive = True
3134
self._ready = False
3235
self._send_queue: queue.Queue[Optional[str]] = queue.Queue()
3336
self._receive_queue: queue.Queue[Optional[str]] = queue.Queue()
37+
38+
# Construct the websocket URL
39+
# Prepend the proxy path to the new URL path
40+
# It will evaluate to "" if nothing's there, and starts with "/path" if present
3441
ws_url = (
35-
url._replace(path=f"/ws/test/{self.id}").geturl()
42+
url._replace(path=f"{proxy_path}/ws/test/{self.id}").geturl()
3643
if register_client
37-
else url._replace(path=f"/ws/connect/{self.id}").geturl()
44+
else url._replace(path=f"{proxy_path}/ws/connect/{self.id}").geturl()
3845
)
3946
self._ws = websocket.WebSocketApp(
4047
ws_url,

0 commit comments

Comments
 (0)