Skip to content

Commit

Permalink
feat: Enable gzip support for event payloads (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed May 2, 2024
1 parent 0da5ac7 commit 24ebf4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions contract-tests/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def status():
'secure-mode-hash',
'tags',
'migrations',
'event-gzip',
'event-sampling',
'polling-gzip',
'inline-context',
Expand Down
5 changes: 4 additions & 1 deletion ldclient/impl/events/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import uuid
import queue
import urllib3
import gzip
from ldclient.config import Config
from datetime import timedelta
from random import Random
Expand Down Expand Up @@ -559,19 +560,21 @@ def _post_events_with_retry(
):
hdrs = _headers(config)
hdrs['Content-Type'] = 'application/json'
hdrs['Content-Encoding'] = 'gzip'
if payload_id:
hdrs['X-LaunchDarkly-Event-Schema'] = str(__CURRENT_EVENT_SCHEMA__)
hdrs['X-LaunchDarkly-Payload-ID'] = payload_id
can_retry = True
context = "posting %s" % events_description
data = gzip.compress(bytes(body, 'utf-8'))
while True:
next_action_message = "will retry" if can_retry else "some events were dropped"
try:
r = http_client.request(
'POST',
uri,
headers=hdrs,
body=body,
body=data,
timeout=urllib3.Timeout(connect=config.http.connect_timeout, read=config.http.read_timeout),
retries=0
)
Expand Down

0 comments on commit 24ebf4d

Please sign in to comment.