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

Allow configuring underlying aiohttp websocket #293

Closed
Closed
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
17 changes: 14 additions & 3 deletions src/engineio/asyncio_client.py
Original file line number Diff line number Diff line change
@@ -62,7 +62,10 @@ class AsyncClient(client.Client):
leave interrupt handling to the calling application.
Interrupt handling can only be enabled when the
client instance is created in the main thread.
:param websocket_options: Dictionary containing optional keyword
arguments passed to aiohttp.ws_connect().
"""

def is_asyncio_based(self):
return True

@@ -304,12 +307,20 @@ async def _connect_websocket(self, url, headers, engineio_path):
ssl_context.verify_mode = ssl.CERT_NONE
ws = await self.http.ws_connect(
websocket_url + self._get_url_timestamp(),
headers=headers, ssl=ssl_context,
timeout=self.request_timeout)
**{
**self.websocket_options,
"headers": headers,
"ssl": ssl_context,
"timeout": self.request_timeout,
})
else:
ws = await self.http.ws_connect(
websocket_url + self._get_url_timestamp(),
headers=headers, timeout=self.request_timeout)
**{
**self.websocket_options,
"headers": headers,
"timeout": self.request_timeout,
})
except (aiohttp.client_exceptions.WSServerHandshakeError,
aiohttp.client_exceptions.ServerConnectionError,
aiohttp.client_exceptions.ClientConnectionError):
18 changes: 14 additions & 4 deletions src/engineio/client.py
Original file line number Diff line number Diff line change
@@ -71,11 +71,14 @@ class Client(object):
leave interrupt handling to the calling application.
Interrupt handling can only be enabled when the
client instance is created in the main thread.
:param websocket_options: Dictionary containing optional keyword arguments
passed to websocket.create_connection().
"""
event_names = ['connect', 'disconnect', 'message']

def __init__(self, logger=False, json=None, request_timeout=5,
http_session=None, ssl_verify=True, handle_sigint=True):
http_session=None, ssl_verify=True, handle_sigint=True,
websocket_options={}):
global original_signal_handler
if handle_sigint and original_signal_handler is None and \
threading.current_thread() == threading.main_thread():
@@ -97,6 +100,7 @@ def __init__(self, logger=False, json=None, request_timeout=5,
self.queue = None
self.state = 'disconnected'
self.ssl_verify = ssl_verify
self.websocket_options = websocket_options

if json is not None:
packet.Packet.json = json
@@ -416,9 +420,15 @@ def _connect_websocket(self, url, headers, engineio_path):
extra_options['sslopt'] = {"cert_reqs": ssl.CERT_NONE}
try:
ws = websocket.create_connection(
websocket_url + self._get_url_timestamp(), header=headers,
cookie=cookies, enable_multithread=True,
timeout=self.request_timeout, **extra_options)
websocket_url + self._get_url_timestamp(),
**{
**self.websocket_options,
"header": headers,
"cookie": cookies,
"enable_multithread": True,
"timeout": self.request_timeout,
**extra_options
})
except (ConnectionError, IOError, websocket.WebSocketException):
if upgrade:
self.logger.warning(