Method: RestClient::Response.fix_encoding

Defined in:
lib/restclient/response.rb

.fix_encoding(response) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/restclient/response.rb', line 50

def self.fix_encoding(response)
  charset = RestClient::Utils.get_encoding_from_headers(response.headers)
  encoding = nil

  begin
    encoding = Encoding.find(charset) if charset
  rescue ArgumentError
    if RestClient.log
      RestClient.log << "No such encoding: #{charset.inspect}"
    end
  end

  return unless encoding

  response.force_encoding(encoding)

  response
end