Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Pass through WebSocket connection arguments in Python WebSocket clients, normalize max message size and ensure set for aiohttp #2187

Merged
merged 1 commit into from
Apr 13, 2023
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
pass through websocket connection arguments in python websocket clien…
…ts, normalize max message size and ensure set for aiohttp, fixes #2185
  • Loading branch information
timkpaine committed Apr 13, 2023
commit a4e2705f9789c505cb81f4b83ebbc77df068b80f
9 changes: 7 additions & 2 deletions python/perspective/perspective/client/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ async def _receive_messages(self):
elif msg.type == aiohttp.WSMsgType.CLOSE:
return

async def connect(self, url, on_message, max_message_size) -> None:
self._ws_cm = self._session.ws_connect(url)
async def connect(self, url, on_message, **websocket_connect_kwargs) -> None:
max_message_size = websocket_connect_kwargs.pop("max_message_size", None) or websocket_connect_kwargs.pop("max_msg_size", None) or 1024 * 1024 * 1024
self._ws_cm = self._session.ws_connect(
url,
max_msg_size=max_message_size,
**websocket_connect_kwargs,
)
self._ws = await self._ws_cm.__aenter__()
self._on_message = on_message
self._task = asyncio.create_task(self._receive_messages())
Expand Down
5 changes: 3 additions & 2 deletions python/perspective/perspective/client/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class PerspectiveTornadoWebsocketConnection(PerspectiveWebsocketConnection):
def __init__(self):
self._ws = None

async def connect(self, url, on_message, max_message_size) -> None:
async def connect(self, url, on_message, **websocket_connect_kwargs) -> None:
self._ws = await websocket_connect(
url,
on_message_callback=on_message,
max_message_size=max_message_size,
max_message_size=websocket_connect_kwargs.pop("max_message_size", 1024 * 1024 * 1024),
**websocket_connect_kwargs,
)

def periodic(self, callback, interval) -> Periodic:
Expand Down
5 changes: 3 additions & 2 deletions python/perspective/perspective/client/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ async def _send_ping(self):
respond with `pong`."""
await self.send("ping")

async def connect(self, url):
async def connect(self, url, **websocket_connect_kwargs):
"""Connect to the remote websocket, and send the `init` message to
assert that the Websocket is alive and accepting connections."""
await self._websocket.connect(
url,
on_message=self.on_message,
max_message_size=1024 * 1024 * 1024,
max_message_size=websocket_connect_kwargs.pop("max_message_size", 1024 * 1024 * 1024),
**websocket_connect_kwargs,
)

await self.send({"id": -1, "cmd": "init"})
Expand Down