Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix issue where protocol was changed for ws and wss if no port was provided. #371

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,8 @@ def _setup_server_pool(self, connect_url: Union[str, List[str]]) -> None:

# In case only endpoint with scheme was set.
# e.g. nats://demo.nats.io or localhost:
if uri.port is None:
# the ws and wss do not need a default port as the transport will assume 80 and 443, respectively
if uri.port is None and uri.scheme not in ("ws", "wss"):
uri = urlparse(f"nats://{uri.hostname}:4222")
except ValueError:
raise errors.Error("nats: invalid connect url option")
Expand Down
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ def test_connect_syntax_sugar(self):
self.assertEqual("", uri.username)
self.assertEqual(None, uri.password)

nc = NATS()
nc._setup_server_pool("ws://localhost")
nc._setup_server_pool("wss://localhost")
self.assertEqual(2, len(nc._server_pool))
self.assertEqual("ws", nc._server_pool[0].uri.scheme)
self.assertEqual(None, nc._server_pool[0].uri.port)
self.assertEqual("wss", nc._server_pool[1].uri.scheme)
self.assertEqual(None, nc._server_pool[1].uri.port)

@async_test
async def test_connect_no_servers_on_connect_init(self):
nc = NATS()
Expand Down