lib/lumberg/format_whm.rb in lumberg-2.0.0.pre8 vs lib/lumberg/format_whm.rb in lumberg-2.0.0.pre9

- old
+ new

@@ -1,5 +1,7 @@ +require 'zlib' + module Lumberg class FormatWhm < Faraday::Response::Middleware def initialize(env, *args, &block) @type = args[0] @@ -7,10 +9,25 @@ @boolean_params = args[2] super(env) end def on_complete(env) - env[:body] = format_response(env[:body]) + encoding = env[:response_headers]['content-encoding'] + + encoding = encoding.to_s.downcase if encoding + + body = case encoding + when 'gzip' + env[:response_headers].delete('content-encoding') + Zlib::GzipReader.new(StringIO.new(env[:body])).read + when 'deflate' + env[:response_headers].delete('content-encoding') + Zlib::Inflate.inflate(env[:body]) + else + env[:body] + end + + env[:body] = format_response body end def response_values(env) {status: env[:status], headers: env[:response_headers], body: env[:body]} end