Skip to content

Commit

Permalink
Httpheaders (#1638)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
oberstet and fungs authored Apr 13, 2024
1 parent 75f3758 commit 1a7aaa9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions autobahn/wamp/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)):
Expand All @@ -252,6 +256,7 @@ def _create_transport(index, transport, check_native_endpoint=None):
serializers=serializer_config,
proxy=proxy,
options=options,
headers=headers,
**kw
)

Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 1a7aaa9

Please sign in to comment.