Skip to content

Commit 2932817

Browse files
authored
fix: set accept-encoding header (#425)
#29
1 parent 1cd185c commit 2932817

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ on:
99

1010
jobs:
1111
test:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-latest
1313
timeout-minutes: 10
1414
steps:
1515
- uses: actions/checkout@v2
1616
- uses: actions/setup-python@v2
1717
with:
1818
python-version: "3.8"
1919

20+
- name: Upgrade pip, setuptools, and wheel
21+
run: python -m pip install --upgrade pip setuptools wheel
22+
2023
- name: Install Deps
2124
run: |
2225
pip install --upgrade pylint

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ip3country==0.3.0
2-
setuptools==78.1.1
2+
setuptools==75.3.2
33
ua_parser==0.10.0
44
user_agents==2.2.0
55
grpcio==1.62.3

statsig/client_initialize_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def map_fnc(entry):
193193
hash_name(targeting_gate_name, hash_algo), None)
194194
if targeting_gate is not None:
195195
result["passes_session_recording_targeting"] = targeting_gate.get("value", False)
196-
if result["passes_session_recording_targeting"] != True:
196+
if not result["passes_session_recording_targeting"]:
197197
can_record = False
198198
sampling_rate = session_replay_info.get("sampling_rate", None)
199199
rand = random.random()

statsig/http_worker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def _prepare_headers(self, headers: Optional[Dict[str, Any]], zipped: bool) -> D
260260
"STATSIG-SDK-TYPE": self.__statsig_metadata["sdkType"],
261261
"STATSIG-SDK-VERSION": self.__statsig_metadata["sdkVersion"],
262262
"STATSIG-RETRY": "0",
263+
"Accept-Encoding": "gzip",
263264
}
264265
if zipped:
265266
base_headers.update({"Content-Encoding": "gzip"})

tests/test_sync_config_fallback.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ def test_fallback_when_dcs_incomplete_read_gzip(self, request_mock):
165165
self.get_gate_and_validate()
166166
self.wait_for_sync_and_validate()
167167

168+
def test_accept_encoding_header(self, mock_request):
169+
headers_verified = False
170+
171+
def verify_headers(url, **kwargs):
172+
nonlocal headers_verified
173+
request_headers = kwargs.get('headers', {})
174+
self.assertEqual(request_headers.get('Accept-Encoding'), 'gzip')
175+
headers_verified = True
176+
return PARSED_CONFIG_SPEC
177+
178+
_network_stub.stub_request_with_function(
179+
"download_config_specs/.*", 200, verify_headers)
180+
181+
options = StatsigOptions(api=_network_stub.host)
182+
statsig.initialize("secret-key", options)
183+
statsig.shutdown()
184+
185+
self.assertTrue(headers_verified, "Headers were not verified")
186+
168187
def wait_for_sync_and_validate(self):
169188
_network_stub.stub_statsig_api_request_with_value("download_config_specs/.*", 200,
170189
UPDATED_TIME_CONFIG_SPEC)

0 commit comments

Comments
 (0)