Skip to content

Commit

Permalink
fix: #72 1、Modify the headers variable initialization method to preve…
Browse files Browse the repository at this point in the history
…nt tokens from being overwritten by the same reference in multiple threads;2、Fixed header variable re-initialization to ensure only one initialization;
  • Loading branch information
Deng2016 committed Nov 11, 2021
1 parent 28e0592 commit 81aedf6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
9 changes: 6 additions & 3 deletions signalrcore/hub/auth_hub_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@


class AuthHubConnection(BaseHubConnection):
def __init__(self, auth_function, headers={}, **kwargs):
self.headers = headers
def __init__(self, auth_function, headers=None, **kwargs):
if headers is None:
self.headers = dict()
else:
self.headers = headers
self.auth_function = auth_function
super(AuthHubConnection, self).__init__(**kwargs)
super(AuthHubConnection, self).__init__(headers=headers, **kwargs)

def start(self):
try:
Expand Down
11 changes: 7 additions & 4 deletions signalrcore/hub/base_hub_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def __init__(
self,
url,
protocol,
headers={},
**kwargs):
self.headers = headers
headers=None,
**kwargs):
if headers is None:
self.headers = dict()
else:
self.headers = headers
self.logger = Helpers.get_logger()
self.handlers = []
self.stream_handlers = []
Expand All @@ -35,7 +38,7 @@ def __init__(
self.transport = WebsocketTransport(
url=url,
protocol=protocol,
headers=headers,
headers=self.headers,
on_message=self.on_message,
**kwargs)

Expand Down
5 changes: 2 additions & 3 deletions signalrcore/hub_connection_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
"access_token_factory": None
}
self.token = None
self.headers = None
self.headers = dict()
self.negotiate_headers = None
self.has_auth_configured = None
self.protocol = None
Expand Down Expand Up @@ -160,11 +160,10 @@ def build(self):
"""
if self.protocol is None:
self.protocol = JsonHubProtocol()
self.headers = {}

if "headers" in self.options.keys()\
and type(self.options["headers"]) is dict:
self.headers = self.options["headers"]
self.headers.update(self.options["headers"])

if self.has_auth_configured:
auth_function = self.options["access_token_factory"]
Expand Down
7 changes: 5 additions & 2 deletions signalrcore/transport/websockets/websocket_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class WebsocketTransport(BaseTransport):
def __init__(self,
url="",
headers={},
headers=None,
keep_alive_interval=15,
reconnection_handler=None,
verify_ssl=False,
Expand All @@ -30,7 +30,10 @@ def __init__(self,
self._thread = None
self.skip_negotiation = skip_negotiation
self.url = url
self.headers = headers
if headers is None:
self.headers = dict()
else:
self.headers = headers
self.handshake_received = False
self.token = None # auth
self.state = ConnectionState.disconnected
Expand Down

0 comments on commit 81aedf6

Please sign in to comment.