Skip to content

Commit 2372a1b

Browse files
committed
Compress requests in HTTP device
1 parent 7e7148b commit 2372a1b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/logtail/log_devices/http.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "base64"
22
require "msgpack"
33
require "net/https"
4+
require "zlib"
45

56
require "logtail/config"
67
require "logtail/log_devices/http/flushable_dropping_sized_queue"
@@ -168,7 +169,7 @@ def verify_delivery!
168169
You can enable internal Logtail debug logging with the following:
169170
170171
Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
171-
MESSAGE
172+
MESSAGE
172173
end
173174
end
174175

@@ -179,7 +180,7 @@ def verify_delivery!
179180
You can enable internal debug logging with the following:
180181
181182
Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
182-
MESSAGE
183+
MESSAGE
183184
end
184185

185186
private
@@ -205,8 +206,10 @@ def build_request(msgs)
205206
req = Net::HTTP::Post.new(path)
206207
req['Authorization'] = authorization_payload
207208
req['Content-Type'] = CONTENT_TYPE
209+
req['Content-Encoding'] = 'gzip'
208210
req['User-Agent'] = USER_AGENT
209-
req.body = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
211+
uncompressed = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
212+
req.body = Zlib::Deflate.deflate(uncompressed)
210213
req
211214
end
212215

0 commit comments

Comments
 (0)