Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class HttpCharset
def initialize(content_type)
@content_type = content_type
end
def encoding
return nil unless @content_type
par = @content_type.split(';').select do |c|
c.split('=').first.strip == 'charset'
end.first
return nil unless par
par.split('=').last.strip
end
def encode(str,to)
atual = encoding
return str unless atual
str.force_encoding(atual).encode(to)
end
end
require 'http_charset'
class Net::HTTPResponse
alias :super_body :body
def body
HttpCharset.new(self['content-type']).encode(super_body,'UTF-8')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.