diff --git a/signalrcore/hub/auth_hub_connection.py b/signalrcore/hub/auth_hub_connection.py index 9be7d01..00b3a5b 100644 --- a/signalrcore/hub/auth_hub_connection.py +++ b/signalrcore/hub/auth_hub_connection.py @@ -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: diff --git a/signalrcore/hub/base_hub_connection.py b/signalrcore/hub/base_hub_connection.py index c9325bf..55d03ca 100644 --- a/signalrcore/hub/base_hub_connection.py +++ b/signalrcore/hub/base_hub_connection.py @@ -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 = [] @@ -35,7 +38,7 @@ def __init__( self.transport = WebsocketTransport( url=url, protocol=protocol, - headers=headers, + headers=self.headers, on_message=self.on_message, **kwargs) diff --git a/signalrcore/hub_connection_builder.py b/signalrcore/hub_connection_builder.py index 1d38cfa..01d88da 100644 --- a/signalrcore/hub_connection_builder.py +++ b/signalrcore/hub_connection_builder.py @@ -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 @@ -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"] diff --git a/signalrcore/transport/websockets/websocket_transport.py b/signalrcore/transport/websockets/websocket_transport.py index 69c67ea..19bf1bb 100644 --- a/signalrcore/transport/websockets/websocket_transport.py +++ b/signalrcore/transport/websockets/websocket_transport.py @@ -17,7 +17,7 @@ class WebsocketTransport(BaseTransport): def __init__(self, url="", - headers={}, + headers=None, keep_alive_interval=15, reconnection_handler=None, verify_ssl=False, @@ -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