Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
Open
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
14 changes: 13 additions & 1 deletion lib/chatmeter/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def request(params, &block)

if response.body && !response.body.empty?
begin
response_body = MultiJson.load(response.body, symbolize_keys: true)
response_body_json = gunzip_response_body(response)
response_body = MultiJson.load(response_body_json, symbolize_keys: true)
rescue
if response.headers['Content-Type'] === 'application/json'
raise
Expand All @@ -105,5 +106,16 @@ def request(params, &block)
@connection.reset
response_body || ""
end

# Chatmeter has started to gzip some (but not all) response bodies. So, now we need to deal with that too.
def gunzip_response_body(response)
if response.headers['Content-Encoding'] == 'gzip'
sio = StringIO.new( response.body )
gz = Zlib::GzipReader.new( sio )
gz.read()
else
response.body
end
end
end
end
2 changes: 1 addition & 1 deletion lib/chatmeter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Chatmeter
VERSION = "1.3.5"
VERSION = "1.4.0-pre"
end