From d366e66909f8c989889e830271faa6c64bd4292a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6ge?= Date: Thu, 7 Mar 2024 12:26:37 +0100 Subject: [PATCH 1/4] feat: pass throught custom http headers as transport configuration --- autobahn/wamp/component.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/autobahn/wamp/component.py b/autobahn/wamp/component.py index 8d5b53bc6..214363e19 100644 --- a/autobahn/wamp/component.py +++ b/autobahn/wamp/component.py @@ -120,8 +120,8 @@ def _create_transport(index, transport, check_native_endpoint=None): valid_transport_keys = [ 'type', 'url', 'endpoint', 'serializer', 'serializers', 'options', 'max_retries', 'max_retry_delay', 'initial_retry_delay', - 'retry_delay_growth', 'retry_delay_jitter', 'proxy', - ] + 'retry_delay_growth', 'retry_delay_jitter', 'proxy', 'headers' + ] for k in transport.keys(): if k not in valid_transport_keys: raise ValueError( @@ -160,6 +160,8 @@ def _create_transport(index, transport, check_native_endpoint=None): raise ValueError( 'options must be a dict, not {}'.format(type(options)) ) + + headers = transport.get("headers", None) if kind == 'websocket': for key in ['url']: @@ -252,6 +254,7 @@ def _create_transport(index, transport, check_native_endpoint=None): serializers=serializer_config, proxy=proxy, options=options, + headers=headers, **kw ) @@ -268,7 +271,8 @@ def __init__(self, idx, kind, url, endpoint, serializers, retry_delay_growth=1.5, retry_delay_jitter=0.1, proxy=None, - options=None): + options=None, + headers=None): """ """ if options is None: @@ -279,6 +283,7 @@ def __init__(self, idx, kind, url, endpoint, serializers, self.url = url self.endpoint = endpoint self.options = options + self.headers = headers self.serializers = serializers if self.type == 'rawsocket' and len(serializers) != 1: From b9773713112107cade5eb0be90c67db868362954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6ge?= Date: Wed, 20 Mar 2024 11:49:24 +0100 Subject: [PATCH 2/4] chore: simplify and add argument check for rawsocket mode --- autobahn/wamp/component.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autobahn/wamp/component.py b/autobahn/wamp/component.py index 214363e19..115b7a371 100644 --- a/autobahn/wamp/component.py +++ b/autobahn/wamp/component.py @@ -161,7 +161,7 @@ def _create_transport(index, transport, check_native_endpoint=None): 'options must be a dict, not {}'.format(type(options)) ) - headers = transport.get("headers", None) + headers = transport.get("headers") if kind == 'websocket': for key in ['url']: @@ -229,6 +229,8 @@ def _create_transport(index, transport, check_native_endpoint=None): endpoint_config = transport['endpoint'] if 'serializers' in transport: raise ValueError("'serializers' is only for websocket; use 'serializer'") + if headers is None: + raise ValueError("'headers' not supported for rawsocket transport") # always a list; len == 1 for rawsocket if 'serializer' in transport: if not isinstance(transport['serializer'], (str, str)): From 7b1db98cc9a8fe5e9c83508140c18a0bba8fde30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6ge?= Date: Thu, 21 Mar 2024 17:11:12 +0100 Subject: [PATCH 3/4] fix: is not None --- autobahn/wamp/component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autobahn/wamp/component.py b/autobahn/wamp/component.py index 115b7a371..1f3ad0603 100644 --- a/autobahn/wamp/component.py +++ b/autobahn/wamp/component.py @@ -229,7 +229,7 @@ def _create_transport(index, transport, check_native_endpoint=None): endpoint_config = transport['endpoint'] if 'serializers' in transport: raise ValueError("'serializers' is only for websocket; use 'serializer'") - if headers is None: + if headers is not None: raise ValueError("'headers' not supported for rawsocket transport") # always a list; len == 1 for rawsocket if 'serializer' in transport: From ac08f2bd6cfe0f31a0582c431e8474fa93d9721c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6ge?= Date: Sun, 24 Mar 2024 13:00:29 +0100 Subject: [PATCH 4/4] fix: flake8 accepted formatting --- autobahn/wamp/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autobahn/wamp/component.py b/autobahn/wamp/component.py index 1f3ad0603..5da892d32 100644 --- a/autobahn/wamp/component.py +++ b/autobahn/wamp/component.py @@ -121,7 +121,7 @@ def _create_transport(index, transport, check_native_endpoint=None): 'type', 'url', 'endpoint', 'serializer', 'serializers', 'options', 'max_retries', 'max_retry_delay', 'initial_retry_delay', 'retry_delay_growth', 'retry_delay_jitter', 'proxy', 'headers' - ] + ] for k in transport.keys(): if k not in valid_transport_keys: raise ValueError( @@ -160,7 +160,7 @@ def _create_transport(index, transport, check_native_endpoint=None): raise ValueError( 'options must be a dict, not {}'.format(type(options)) ) - + headers = transport.get("headers") if kind == 'websocket':