Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable Accept-Encoding header on all requests #257

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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