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

Allow HTTP protocol for Nominatim lookup

but default to HTTPS (custom hosts may not support HTTPS).
This partially reverts 7cb0acc9.
parent bfa34249
No related branches found
No related tags found
No related merge requests found
......@@ -13,15 +13,15 @@ module Geocoder::Lookup
def query_url(query)
method = query.reverse_geocode? ? "reverse" : "search"
"#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
end
def supported_protocols
[:http, :https]
"#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
end
private
def configured_host
configuration[:host] || "locationiq.org"
end
def results(query)
return [] unless doc = fetch_data(query)
......
......@@ -14,15 +14,23 @@ module Geocoder::Lookup
def query_url(query)
method = query.reverse_geocode? ? "reverse" : "search"
host = configuration[:host] || "nominatim.openstreetmap.org"
"#{protocol}://#{host}/#{method}?" + url_query_string(query)
"#{protocol}://#{configured_host}/#{method}?" + url_query_string(query)
end
def supported_protocols
[:https]
private # ---------------------------------------------------------------
def configured_host
configuration[:host] || "nominatim.openstreetmap.org"
end
private # ---------------------------------------------------------------
def use_ssl?
# nominatim.openstreetmap.org redirects HTTP requests to HTTPS
if configured_host == "nominatim.openstreetmap.org"
true
else
super
end
end
def results(query)
return [] unless doc = fetch_data(query)
......
......@@ -37,7 +37,7 @@ class NominatimTest < GeocoderTestCase
def test_host_configuration
Geocoder.configure(nominatim: {host: "local.com"})
query = Geocoder::Query.new("Bluffton, SC")
assert_match %r(https://local\.com), query.url
assert_match %r(http://local\.com), query.url
end
def test_raises_exception_when_over_query_limit
......
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