Skip to content

Commit

Permalink
feat: Enable gzip support for event payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Apr 11, 2024
1 parent 30b7ac0 commit 82e5bd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'secure-mode-hash',
'tags',
'migrations',
'event-gzip',
'event-sampling',
'context-comparison',
'polling-gzip',
Expand Down
1 change: 1 addition & 0 deletions launchdarkly-server-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "semantic", "~> 1.6"
spec.add_runtime_dependency "concurrent-ruby", "~> 1.1"
spec.add_runtime_dependency "ld-eventsource", "2.2.2"
spec.add_runtime_dependency "zlib", "~> 3.1"
# Please keep ld-eventsource dependency as an exact version so that bugfixes to
# that LD library are always associated with a new SDK version.

Expand Down
5 changes: 4 additions & 1 deletion lib/ldclient-rb/impl/event_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ def send_event_data(event_data, description, is_diagnostic)
@logger.debug { "[LDClient] sending #{description}: #{event_data}" }
headers = {}
headers["content-type"] = "application/json"
headers["content-encoding"] = "gzip"
Impl::Util.default_http_headers(@sdk_key, @config).each { |k, v| headers[k] = v }
unless is_diagnostic
headers["X-LaunchDarkly-Event-Schema"] = CURRENT_SCHEMA_VERSION.to_s
headers["X-LaunchDarkly-Payload-ID"] = payload_id
end
gzip = Zlib::GzipWriter.new(StringIO.new)
gzip << event_data
response = http_client.request("POST", uri, {
headers: headers,
body: event_data,
body: gzip.close.string,
})
rescue StandardError => exn
@logger.warn { "[LDClient] Error sending events: #{exn.inspect}." }
Expand Down

0 comments on commit 82e5bd4

Please sign in to comment.