lib/zendesk_api/middleware/response/gzip.rb in zendesk_api-1.2.10 vs lib/zendesk_api/middleware/response/gzip.rb in zendesk_api-1.3.0.rc1

- old
+ new

@@ -1,21 +1,18 @@ -require 'faraday_middleware/response_middleware' require 'zlib' require 'stringio' module ZendeskAPI # @private module Middleware # @private module Response # Faraday middleware to handle content-encoding = gzip - class Gzip < FaradayMiddleware::ResponseMiddleware - define_parser do |body| - Zlib::GzipReader.new(StringIO.new(body)).read - end - - def parse_response?(env) - super && env[:response_headers]['content-encoding'] == "gzip" + class Gzip < Faraday::Response::Middleware + def on_complete(env) + if env[:body].respond_to?(:to_str) && !env[:body].strip.empty? && env[:response_headers]['content-encoding'] == "gzip" + env[:body] = Zlib::GzipReader.new(StringIO.new(env[:body])).read + end end end end end end