From 24ebf4dc90d7358bbfbe10b322f7198096f8401a Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Thu, 2 May 2024 13:02:12 -0400 Subject: [PATCH] feat: Enable gzip support for event payloads (#286) --- contract-tests/service.py | 1 + ldclient/impl/events/event_processor.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/contract-tests/service.py b/contract-tests/service.py index 201d5b2..fd50cc1 100644 --- a/contract-tests/service.py +++ b/contract-tests/service.py @@ -70,6 +70,7 @@ def status(): 'secure-mode-hash', 'tags', 'migrations', + 'event-gzip', 'event-sampling', 'polling-gzip', 'inline-context', diff --git a/ldclient/impl/events/event_processor.py b/ldclient/impl/events/event_processor.py index b86b74b..ad5fde3 100644 --- a/ldclient/impl/events/event_processor.py +++ b/ldclient/impl/events/event_processor.py @@ -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 @@ -559,11 +560,13 @@ 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: @@ -571,7 +574,7 @@ def _post_events_with_retry( 'POST', uri, headers=hdrs, - body=body, + body=data, timeout=urllib3.Timeout(connect=config.http.connect_timeout, read=config.http.read_timeout), retries=0 )