Skip to content
Snippets Groups Projects
Commit 332dcbe9 authored by Tim Robertson's avatar Tim Robertson
Browse files

read and apply charset from Content-Type to geocoder raw response, if possible.

parent d35b9d7b
No related branches found
No related tags found
No related merge requests found
...@@ -194,6 +194,19 @@ module Geocoder ...@@ -194,6 +194,19 @@ module Geocoder
check_api_key_configuration!(query) check_api_key_configuration!(query)
response = make_api_request(query) response = make_api_request(query)
body = response.body body = response.body
# apply the charset from the Content-Type header, if possible
ct = response['content-type']
if ct && ct['charset']
charset = ct.split(';').select do |s|
s['charset']
end.first.to_s.split('=')
if charset.length == 2
body.force_encoding(charset.last) rescue ArgumentError
end
end
if cache and (200..399).include?(response.code.to_i) if cache and (200..399).include?(response.code.to_i)
cache[key] = body cache[key] = body
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment