Skip to content

Commit 74e3b6e

Browse files
committed
Compress requests in HTTP device ✅
1 parent 2372a1b commit 74e3b6e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

spec/logtail/log_devices/http_spec.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
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-
expect(request_attempt.request.body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))
105+
decompressed_body = Zlib::Inflate.inflate(request_attempt.request.body)
106+
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"))
106107

107108
message_queue = http.instance_variable_get(:@msg_queue)
108109
expect(message_queue.size).to eq(0)
@@ -126,14 +127,16 @@
126127

127128
it "should deliver requests on an interval" do
128129
stub = stub_request(:post, "https://in.logs.betterstack.com/").
129-
with(
130-
:body => start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
131-
:headers => {
132-
'Authorization' => 'Bearer MYKEY',
133-
'Content-Type' => 'application/msgpack',
134-
'User-Agent' => "Logtail Ruby/#{Logtail::VERSION} (HTTP)"
135-
}
136-
).
130+
with do |request|
131+
decompressed_body = Zlib::Inflate.inflate(request.body)
132+
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"))
133+
134+
expect(request.headers['Authorization']).to eq('Bearer MYKEY')
135+
expect(request.headers['Content-Type']).to eq('application/msgpack')
136+
expect(request.headers['User-Agent']).to eq("Logtail Ruby/#{Logtail::VERSION} (HTTP)")
137+
138+
true
139+
end.
137140
to_return(:status => 200, :body => "", :headers => {})
138141

139142
http = described_class.new("MYKEY", flush_interval: 0.1)

0 commit comments

Comments
 (0)