Sha256: a0a2fe9124a4410d68339e1488a404b1ddc3c296d49415c26e1ba92391f1aee0

Contents?: true

Size: 789 Bytes

Versions: 13

Compression:

Stored size: 789 Bytes

Contents

require 'faraday'
require 'zlib'
 
module Google
  class APIClient
    class Charset < Faraday::Response::Middleware
      include Google::APIClient::Logging

      def charset_for_content_type(type)
        if type
          m = type.match(/(?:charset|encoding)="?([a-z0-9-]+)"?/i)
          if m
            return Encoding.find(m[1])
          end
        end
        nil
      end

      def adjust_encoding(env)
        charset = charset_for_content_type(env[:response_headers]['content-type'])
        if charset && env[:body].encoding != charset
          env[:body].force_encoding(charset)
        end
      end
      
      def on_complete(env)
        adjust_encoding(env)
      end
    end
  end
end
 
Faraday::Response.register_middleware :charset => Google::APIClient::Charset

Version data entries

13 entries across 13 versions & 3 rubygems

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