Skip to content
Snippets Groups Projects
Commit 0e157f67 authored by Alex Reisner's avatar Alex Reisner
Browse files

Only cache response if successful.

parent 6e631499
Branches
Tags
No related merge requests found
...@@ -146,15 +146,16 @@ module Geocoder ...@@ -146,15 +146,16 @@ module Geocoder
timeout(Geocoder::Configuration.timeout) do timeout(Geocoder::Configuration.timeout) do
url = query_url(query, reverse) url = query_url(query, reverse)
uri = URI.parse(url) uri = URI.parse(url)
unless cache and response = cache[url] unless cache and body = cache[url]
client = http_client.new(uri.host, uri.port) client = http_client.new(uri.host, uri.port)
client.use_ssl = true if Geocoder::Configuration.use_https client.use_ssl = true if Geocoder::Configuration.use_https
response = client.get(uri.request_uri).body response = client.get(uri.request_uri)
if cache body = response.body
cache[url] = response if cache and (200..399).include?(response.code.to_i)
cache[url] = body
end end
end end
response body
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment