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