Skip to content

Commit 2c2e4fa

Browse files
authored
feat: Enable Accept-Encoding header on all requests (#259)
1 parent dc5a6ba commit 2c2e4fa

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

ldclient/impl/http.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def _application_header_value(application: dict) -> str:
1919

2020
def _base_headers(config):
2121
headers = {'Authorization': config.sdk_key or '',
22-
'User-Agent': 'PythonClient/' + VERSION}
22+
'User-Agent': 'PythonClient/' + VERSION,
23+
'Accept-Encoding': 'gzip'
24+
}
2325

2426
app_value = _application_header_value(config.application)
2527
if app_value:

testing/impl/datasource/test_feature_requester.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_get_all_data_returns_data():
99
with start_server() as server:
1010
config = Config(sdk_key = 'sdk-key', base_uri = server.uri)
1111
fr = FeatureRequesterImpl(config)
12-
12+
1313
flags = { 'flag1': { 'key': 'flag1' } }
1414
segments = { 'segment1': { 'key': 'segment1' } }
1515
resp_data = { 'flags': flags, 'segments': segments }
@@ -31,6 +31,7 @@ def test_get_all_data_sends_headers():
3131
req = server.require_request()
3232
assert req.headers['Authorization'] == 'sdk-key'
3333
assert req.headers['User-Agent'] == 'PythonClient/' + VERSION
34+
assert req.headers['Accept-Encoding'] == 'gzip'
3435
assert req.headers.get('X-LaunchDarkly-Wrapper') is None
3536
assert req.headers.get('X-LaunchDarkly-Tags') is None
3637

testing/impl/datasource/test_streaming.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_request_properties():
4343
assert req.method == 'GET'
4444
assert req.headers.get('Authorization') == 'sdk-key'
4545
assert req.headers.get('User-Agent') == 'PythonClient/' + VERSION
46+
assert req.headers['Accept-Encoding'] == 'gzip'
4647
assert req.headers.get('X-LaunchDarkly-Wrapper') is None
4748
assert req.headers.get('X-LaunchDarkly-Tags') is None
4849

testing/impl/events/test_event_processor.py

+8
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ def test_sdk_key_is_sent():
479479

480480
assert mock_http.request_headers.get('Authorization') == 'SDK_KEY'
481481

482+
def test_default_headers_are_send():
483+
with DefaultTestProcessor() as ep:
484+
ep.send_event(EventInputIdentify(timestamp, context))
485+
ep.flush()
486+
ep._wait_until_inactive()
487+
488+
assert mock_http.request_headers.get('Accept-Encoding') == 'gzip'
489+
482490
def test_wrapper_header_not_sent_when_not_set():
483491
with DefaultTestProcessor() as ep:
484492
ep.send_event(EventInputIdentify(timestamp, context))

0 commit comments

Comments
 (0)