Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/client-python/src/rocketride/mixins/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ def _get_websocket_uri(uri: str) -> str:
parsed = urllib.parse.urlparse(normalized)

ws_scheme = 'wss' if parsed.scheme in ('https', 'wss') else 'ws'
ws_uri = parsed._replace(scheme=ws_scheme)
return f'{ws_uri.geturl()}/task/service'
path = parsed.path.rstrip('/')
if not path.endswith('/task/service'):
path = f'{path}/task/service' if path else '/task/service'
ws_uri = parsed._replace(scheme=ws_scheme, path=path)
return ws_uri.geturl()

def _set_uri(self, uri: str) -> None:
"""Update the server URI (internal)."""
Expand Down
18 changes: 18 additions & 0 deletions packages/client-python/tests/test_connection_uri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

from rocketride.mixins.connection import ConnectionMixin


@pytest.mark.parametrize(
('input_uri', 'expected_uri'),
[
('https://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'),
('https://cloud.rocketride.ai/', 'wss://cloud.rocketride.ai/task/service'),
('wss://cloud.rocketride.ai/task/service', 'wss://cloud.rocketride.ai/task/service'),
('ws://localhost:5565', 'ws://localhost:5565/task/service'),
('ws://localhost:5565/', 'ws://localhost:5565/task/service'),
('ws://localhost:5565/task/service', 'ws://localhost:5565/task/service'),
],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)
def test_get_websocket_uri_normalizes_task_service_path(input_uri, expected_uri):
assert ConnectionMixin._get_websocket_uri(input_uri) == expected_uri
Loading