Skip to content

Commit 72d396e

Browse files
committed
switch from deflate to gzip
1 parent 2ec401c commit 72d396e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/logtail/log_devices/http.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,14 @@ def build_request(msgs)
206206
req = Net::HTTP::Post.new(path)
207207
req['Authorization'] = authorization_payload
208208
req['Content-Type'] = CONTENT_TYPE
209-
req['Content-Encoding'] = 'deflate'
209+
req['Content-Encoding'] = 'gzip'
210210
req['User-Agent'] = USER_AGENT
211211
uncompressed = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
212-
req.body = Zlib::Deflate.deflate(uncompressed, Zlib::BEST_SPEED)
212+
string_io = StringIO.new
213+
Zlib::GzipWriter.wrap(string_io) do |gz|
214+
gz.write(uncompressed)
215+
end
216+
req.body = string_io.string
213217
req
214218
end
215219

spec/logtail/log_devices/http_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
request_queue = http.instance_variable_get(:@request_queue)
103103
request_attempt = request_queue.deq
104104
expect(request_attempt.request).to be_kind_of(Net::HTTP::Post)
105-
decompressed_body = Zlib::Inflate.inflate(request_attempt.request.body)
105+
decompressed_body = Zlib::GzipReader.new(StringIO.new(request_attempt.request.body)).read
106106
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))
107107

108108
message_queue = http.instance_variable_get(:@msg_queue)
@@ -128,7 +128,7 @@
128128
it "should deliver requests on an interval" do
129129
stub = stub_request(:post, "https://in.logs.betterstack.com/").
130130
with do |request|
131-
decompressed_body = Zlib::Inflate.inflate(request.body)
131+
decompressed_body = Zlib::GzipReader.new(StringIO.new(request.body)).read
132132
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))
133133

134134
expect(request.headers['Authorization']).to eq('Bearer MYKEY')

0 commit comments

Comments
 (0)