6 class Charset < Faraday::Middleware
7 include Google::APIClient::Logging
9 def charset_for_content_type(type)
11 m = type.match(/(?:charset|encoding)="?([a-z0-9-]+)"?/i)
13 return Encoding.find(m[1])
19 def adjust_encoding(env)
20 charset = charset_for_content_type(env[:response_headers]['content-type'])
21 if charset && env[:body].encoding != charset
22 env[:body].force_encoding(charset)
33 Faraday::Response.register_middleware :charset => Google::APIClient::Charset