Skip to content

Commit ac77af4

Browse files
authored
feat: add user-agent header (#5)
1 parent e2819fa commit ac77af4

6 files changed

Lines changed: 18 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ First, install the FeatureProbe SDK as a dependency in your application.
4646
#### pip
4747

4848
```bash
49-
pip3 install featureprobe-server
49+
pip3 install featureprobe-server-sdk-python
5050
```
5151

52-
> You may get the latest version of this repo (not released) via [TestPyPI](https://test.pypi.org/project/featureprobe-server/)
52+
> You may get the latest version of this repo (not released) via [TestPyPI](https://test.pypi.org/project/featureprobe-server-sdk-python/)
5353
5454
<!-- WIP
5555
#### conda
5656
5757
Will be supported later.
5858
5959
```bash
60-
conda install featureprobe-server
60+
conda install featureprobe-server-sdk-python
6161
```
6262
-->
6363

featureprobe/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040

4141
__all__ = [
42+
'__version__',
43+
4244
# featureprobe.model
4345

4446
'Condition',
@@ -58,6 +60,7 @@
5860
'Toggle',
5961

6062
# featureprobe
63+
6164
'AccessCounter',
6265
'AccessRecorder',
6366
'Client',

featureprobe/context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Context:
2323
_POST_EVENTS_DATA_API = '/api/events'
2424

2525
def __init__(self, sdk_key: str, config: "Config"):
26+
from featureprobe import __version__
2627
self._synchronizer_url = config.synchronizer_url or (
2728
config.remote_uri + self._GET_REPOSITORY_DATA_API)
2829
self._event_url = config.event_url or (
@@ -31,6 +32,10 @@ def __init__(self, sdk_key: str, config: "Config"):
3132
self._refresh_interval = config.refresh_interval
3233
self._location = config.location
3334
self._http_config = config.http_config
35+
self._headers = {
36+
'Authorization': sdk_key,
37+
'user-agent': 'Python/' + str(__version__),
38+
}
3439

3540
@property
3641
def synchronizer_url(self):
@@ -55,3 +60,7 @@ def location(self):
5560
@property
5661
def http_config(self):
5762
return self._http_config
63+
64+
@property
65+
def headers(self):
66+
return self._headers

featureprobe/default_event_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, context: Context):
9797
self._session = Session()
9898
self._session.mount('http://', context.http_config.adapter)
9999
self._session.mount('https://', context.http_config.adapter)
100-
self._session.headers.update({'Authorization': context.sdk_key})
100+
self._session.headers.update(context.headers)
101101
self._timeout = (
102102
context.http_config.conn_timeout,
103103
context.http_config.read_timeout)

featureprobe/pooling_synchronizer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
class PoolingSynchronizer(Synchronizer):
3333
__logger = logging.getLogger('FeatureProbe-Synchronizer')
3434

35-
_GET_SDK_KEY_HEADER = 'Authorization'
36-
3735
def __init__(self, context: "Context", data_repo: "DataRepository"):
3836
self._refresh_interval = context.refresh_interval
3937
self._api_url = context.synchronizer_url
@@ -42,8 +40,7 @@ def __init__(self, context: "Context", data_repo: "DataRepository"):
4240
self._session = Session()
4341
self._session.mount('http://', context.http_config.adapter)
4442
self._session.mount('https://', context.http_config.adapter)
45-
self._session.headers.update(
46-
{PoolingSynchronizer._GET_SDK_KEY_HEADER: context.sdk_key})
43+
self._session.headers.update(context.headers)
4744
self._timeout = (
4845
context.http_config.conn_timeout,
4946
context.http_config.read_timeout)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _requirements():
4242
pypi_classifiers.append('Development Status :: 5 - Production/Stable')
4343

4444
setup(
45-
name='featureprobe-server',
45+
name='featureprobe-server-sdk-python',
4646
version=featureprobe.__version__,
4747

4848
author='FeatureProbe',

0 commit comments

Comments
 (0)