From 537b240558321198796c248a7c7487e2b4dfbf52 Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Wed, 24 Jan 2024 15:43:35 -0500 Subject: [PATCH] feat: Enable Accept-Encoding header on all requests (#257) --- ldclient/impl/http.py | 4 +++- testing/impl/datasource/test_feature_requester.py | 3 ++- testing/impl/datasource/test_streaming.py | 1 + testing/impl/events/test_event_processor.py | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ldclient/impl/http.py b/ldclient/impl/http.py index 858fd371..9ebb0102 100644 --- a/ldclient/impl/http.py +++ b/ldclient/impl/http.py @@ -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: diff --git a/testing/impl/datasource/test_feature_requester.py b/testing/impl/datasource/test_feature_requester.py index 2deb47b2..a38a31f6 100644 --- a/testing/impl/datasource/test_feature_requester.py +++ b/testing/impl/datasource/test_feature_requester.py @@ -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 } @@ -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 diff --git a/testing/impl/datasource/test_streaming.py b/testing/impl/datasource/test_streaming.py index 8e449d25..f18a43e4 100644 --- a/testing/impl/datasource/test_streaming.py +++ b/testing/impl/datasource/test_streaming.py @@ -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 diff --git a/testing/impl/events/test_event_processor.py b/testing/impl/events/test_event_processor.py index 15e95bba..3c4ac1f8 100644 --- a/testing/impl/events/test_event_processor.py +++ b/testing/impl/events/test_event_processor.py @@ -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))