Sha256: 50c9006d47b7ebbf399d95795eae0a83644a4c55fad070fef066dcb617b1cd8b

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

require 'faraday'
require 'zlib'
 
module Google
  class APIClient
    class Gzip < Faraday::Response::Middleware
      include Google::APIClient::Logging
 
      def on_complete(env)
        encoding = env[:response_headers]['content-encoding'].to_s.downcase
        case encoding
        when 'gzip'
          logger.debug { "Decompressing gzip encoded response (#{env[:body].length} bytes)" }        
          env[:body] = Zlib::GzipReader.new(StringIO.new(env[:body])).read
          env[:response_headers].delete('content-encoding')
          logger.debug { "Decompressed (#{env[:body].length} bytes)" }        
        when 'deflate'
          logger.debug{ "Decompressing deflate encoded response (#{env[:body].length} bytes)" }        
          env[:body] = Zlib::Inflate.inflate(env[:body])
          env[:response_headers].delete('content-encoding')
          logger.debug { "Decompressed (#{env[:body].length} bytes)" }        
        end
      end
    end
  end
end
 
Faraday::Response.register_middleware :gzip => Google::APIClient::Gzip

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
arvados-google-api-client-0.8.7.4 lib/google/api_client/gzip.rb
arvados-google-api-client-0.8.7.3 lib/google/api_client/gzip.rb
arvados-google-api-client-0.8.7.2 lib/google/api_client/gzip.rb
cure-google-api-client-0.8.7.1 lib/google/api_client/gzip.rb
google-api-client-0.8.7 lib/google/api_client/gzip.rb
jomz-google-api-client-0.7.1 lib/google/api_client/gzip.rb
google-api-client-0.8.6 lib/google/api_client/gzip.rb
google-api-client-0.8.5 lib/google/api_client/gzip.rb
google-api-client-0.8.4 lib/google/api_client/gzip.rb
google-api-client-0.8.3 lib/google/api_client/gzip.rb
google-api-client-0.8.2 lib/google/api_client/gzip.rb
google-api-client-0.8.1.1 lib/google/api_client/gzip.rb
google-api-client-0.8.1 lib/google/api_client/gzip.rb
google-api-client-0.8.0 lib/google/api_client/gzip.rb
google-api-client-0.7.1 lib/google/api_client/gzip.rb
google-api-client-0.7.0 lib/google/api_client/gzip.rb
google-api-client-0.7.0.rc2 lib/google/api_client/gzip.rb