Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/logtail/log_devices/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ def build_request(msgs)
req = Net::HTTP::Post.new(path)
req['Authorization'] = authorization_payload
req['Content-Type'] = CONTENT_TYPE
req['Content-Encoding'] = 'deflate'
req['Content-Encoding'] = 'gzip'
req['User-Agent'] = USER_AGENT
uncompressed = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
req.body = Zlib::Deflate.deflate(uncompressed, Zlib::BEST_SPEED)
string_io = StringIO.new
Zlib::GzipWriter.wrap(string_io) do |gz|
gz.write(uncompressed)
end
req.body = string_io.string
req
end

Expand Down
6 changes: 0 additions & 6 deletions logtail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('rspec-its', '>= 0')
spec.add_development_dependency('timecop', '>= 0')
spec.add_development_dependency('webmock', '~> 2.3')

if RUBY_PLATFORM == "java"
spec.add_development_dependency('activerecord-jdbcsqlite3-adapter', '>= 0')
else
spec.add_development_dependency('sqlite3', '>= 0')
end
end
8 changes: 4 additions & 4 deletions spec/logtail/log_devices/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
request_queue = http.instance_variable_get(:@request_queue)
request_attempt = request_queue.deq
expect(request_attempt.request).to be_kind_of(Net::HTTP::Post)
decompressed_body = Zlib::Inflate.inflate(request_attempt.request.body)
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"))
decompressed_body = Zlib::GzipReader.new(StringIO.new(request_attempt.request.body)).read
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1")

message_queue = http.instance_variable_get(:@msg_queue)
expect(message_queue.size).to eq(0)
Expand All @@ -128,8 +128,8 @@
it "should deliver requests on an interval" do
stub = stub_request(:post, "https://in.logs.betterstack.com/").
with do |request|
decompressed_body = Zlib::Inflate.inflate(request.body)
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"))
decompressed_body = Zlib::GzipReader.new(StringIO.new(request.body)).read
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1")

expect(request.headers['Authorization']).to eq('Bearer MYKEY')
expect(request.headers['Content-Type']).to eq('application/msgpack')
Expand Down
Loading