44from enum import Enum
55from splitio .push .sse import SSEClient , SSE_EVENT_ERROR
66from splitio .util .threadutil import EventGroup
7+ from splitio .api import headers_from_metadata
78
89
910_LOGGER = logging .getLogger (__name__ )
@@ -20,14 +21,18 @@ class _Status(Enum):
2021 ERRORED = 2
2122 CONNECTED = 3
2223
23- def __init__ (self , event_callback , first_event_callback = None ,
24- connection_closed_callback = None , base_url = 'https://streaming.split.io' ):
24+ def __init__ (self , event_callback , sdk_metadata , first_event_callback = None ,
25+ connection_closed_callback = None , client_key = None ,
26+ base_url = 'https://streaming.split.io' ):
2527 """
2628 Construct a split sse client.
2729
2830 :param callback: fuction to call when an event is received.
2931 :type callback: callable
3032
33+ :param sdk_metadata: SDK version & machine name & IP.
34+ :type sdk_metadata: splitio.client.util.SdkMetadata
35+
3136 :param first_event_callback: function to call when the first event is received.
3237 :type first_event_callback: callable
3338
@@ -36,6 +41,9 @@ def __init__(self, event_callback, first_event_callback=None,
3641
3742 :param base_url: scheme + :// + host
3843 :type base_url: str
44+
45+ :param client_key: client key.
46+ :type client_key: str
3947 """
4048 self ._client = SSEClient (self ._raw_event_handler )
4149 self ._callback = event_callback
@@ -45,6 +53,7 @@ def __init__(self, event_callback, first_event_callback=None,
4553 self ._status = SplitSSEClient ._Status .IDLE
4654 self ._sse_first_event = None
4755 self ._sse_connection_closed = None
56+ self ._metadata = headers_from_metadata (sdk_metadata , client_key )
4857
4958 def _raw_event_handler (self , event ):
5059 """
@@ -117,7 +126,8 @@ def start(self, token):
117126 def connect (url ):
118127 """Connect to sse in a blocking manner."""
119128 try :
120- self ._client .start (url , timeout = self .KEEPALIVE_TIMEOUT )
129+ self ._client .start (url , timeout = self .KEEPALIVE_TIMEOUT ,
130+ extra_headers = self ._metadata )
121131 finally :
122132 self ._status = SplitSSEClient ._Status .IDLE
123133 self ._sse_connection_closed .set ()
0 commit comments