Skip to content

Commit

Permalink
feat: Enable Accept-Encoding header on all requests (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored Jan 24, 2024
1 parent 406cf6b commit 537b240
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ldclient/impl/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def _application_header_value(application: dict) -> str:

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

app_value = _application_header_value(config.application)
if app_value:
Expand Down
3 changes: 2 additions & 1 deletion testing/impl/datasource/test_feature_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_get_all_data_returns_data():
with start_server() as server:
config = Config(sdk_key = 'sdk-key', base_uri = server.uri)
fr = FeatureRequesterImpl(config)

flags = { 'flag1': { 'key': 'flag1' } }
segments = { 'segment1': { 'key': 'segment1' } }
resp_data = { 'flags': flags, 'segments': segments }
Expand All @@ -31,6 +31,7 @@ def test_get_all_data_sends_headers():
req = server.require_request()
assert req.headers['Authorization'] == 'sdk-key'
assert req.headers['User-Agent'] == 'PythonClient/' + VERSION
assert req.headers['Accept-Encoding'] == 'gzip'
assert req.headers.get('X-LaunchDarkly-Wrapper') is None
assert req.headers.get('X-LaunchDarkly-Tags') is None

Expand Down
1 change: 1 addition & 0 deletions testing/impl/datasource/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_request_properties():
assert req.method == 'GET'
assert req.headers.get('Authorization') == 'sdk-key'
assert req.headers.get('User-Agent') == 'PythonClient/' + VERSION
assert req.headers['Accept-Encoding'] == 'gzip'
assert req.headers.get('X-LaunchDarkly-Wrapper') is None
assert req.headers.get('X-LaunchDarkly-Tags') is None

Expand Down
8 changes: 8 additions & 0 deletions testing/impl/events/test_event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ def test_sdk_key_is_sent():

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

def test_default_headers_are_send():
with DefaultTestProcessor() as ep:
ep.send_event(EventInputIdentify(timestamp, context))
ep.flush()
ep._wait_until_inactive()

assert mock_http.request_headers.get('Accept-Encoding') == 'gzip'

def test_wrapper_header_not_sent_when_not_set():
with DefaultTestProcessor() as ep:
ep.send_event(EventInputIdentify(timestamp, context))
Expand Down

0 comments on commit 537b240

Please sign in to comment.