Skip to content

Commit 24ebf4d

Browse files
authored
feat: Enable gzip support for event payloads (#286)
1 parent 0da5ac7 commit 24ebf4d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

contract-tests/service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def status():
7070
'secure-mode-hash',
7171
'tags',
7272
'migrations',
73+
'event-gzip',
7374
'event-sampling',
7475
'polling-gzip',
7576
'inline-context',

ldclient/impl/events/event_processor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import uuid
1313
import queue
1414
import urllib3
15+
import gzip
1516
from ldclient.config import Config
1617
from datetime import timedelta
1718
from random import Random
@@ -559,19 +560,21 @@ def _post_events_with_retry(
559560
):
560561
hdrs = _headers(config)
561562
hdrs['Content-Type'] = 'application/json'
563+
hdrs['Content-Encoding'] = 'gzip'
562564
if payload_id:
563565
hdrs['X-LaunchDarkly-Event-Schema'] = str(__CURRENT_EVENT_SCHEMA__)
564566
hdrs['X-LaunchDarkly-Payload-ID'] = payload_id
565567
can_retry = True
566568
context = "posting %s" % events_description
569+
data = gzip.compress(bytes(body, 'utf-8'))
567570
while True:
568571
next_action_message = "will retry" if can_retry else "some events were dropped"
569572
try:
570573
r = http_client.request(
571574
'POST',
572575
uri,
573576
headers=hdrs,
574-
body=body,
577+
body=data,
575578
timeout=urllib3.Timeout(connect=config.http.connect_timeout, read=config.http.read_timeout),
576579
retries=0
577580
)

0 commit comments

Comments
 (0)