From 1a7aaa9d90929a37e52f004e5d952490b185c305 Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Sat, 13 Apr 2024 11:19:52 +0200 Subject: [PATCH] Httpheaders (#1638) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: pass throught custom http headers as transport configuration * chore: simplify and add argument check for rawsocket mode * fix: is not None * fix: flake8 accepted formatting --------- Co-authored-by: Johannes Dröge --- autobahn/wamp/component.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autobahn/wamp/component.py b/autobahn/wamp/component.py index 8d5b53bc6..5da892d32 100644 --- a/autobahn/wamp/component.py +++ b/autobahn/wamp/component.py @@ -120,7 +120,7 @@ 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: @@ -161,6 +161,8 @@ def _create_transport(index, transport, check_native_endpoint=None): 'options must be a dict, not {}'.format(type(options)) ) + headers = transport.get("headers") + if kind == 'websocket': for key in ['url']: if key not in transport: @@ -227,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 not 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)): @@ -252,6 +256,7 @@ def _create_transport(index, transport, check_native_endpoint=None): serializers=serializer_config, proxy=proxy, options=options, + headers=headers, **kw ) @@ -268,7 +273,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 +285,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: