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
Branches
Tags
No related merge requests found
...@@ -13,15 +13,15 @@ module Geocoder::Lookup ...@@ -13,15 +13,15 @@ module Geocoder::Lookup
def query_url(query) def query_url(query)
method = query.reverse_geocode? ? "reverse" : "search" method = query.reverse_geocode? ? "reverse" : "search"
"#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) "#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
end
def supported_protocols
[:http, :https]
end end
private private
def configured_host
configuration[:host] || "locationiq.org"
end
def results(query) def results(query)
return [] unless doc = fetch_data(query) return [] unless doc = fetch_data(query)
......
...@@ -14,15 +14,23 @@ module Geocoder::Lookup ...@@ -14,15 +14,23 @@ module Geocoder::Lookup
def query_url(query) def query_url(query)
method = query.reverse_geocode? ? "reverse" : "search" method = query.reverse_geocode? ? "reverse" : "search"
host = configuration[:host] || "nominatim.openstreetmap.org" "#{protocol}://#{configured_host}/#{method}?" + url_query_string(query)
"#{protocol}://#{host}/#{method}?" + url_query_string(query)
end end
def supported_protocols private # ---------------------------------------------------------------
[:https]
def configured_host
configuration[:host] || "nominatim.openstreetmap.org"
end 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) def results(query)
return [] unless doc = fetch_data(query) return [] unless doc = fetch_data(query)
......
...@@ -37,7 +37,7 @@ class NominatimTest < GeocoderTestCase ...@@ -37,7 +37,7 @@ class NominatimTest < GeocoderTestCase
def test_host_configuration def test_host_configuration
Geocoder.configure(nominatim: {host: "local.com"}) Geocoder.configure(nominatim: {host: "local.com"})
query = Geocoder::Query.new("Bluffton, SC") query = Geocoder::Query.new("Bluffton, SC")
assert_match %r(https://local\.com), query.url assert_match %r(http://local\.com), query.url
end end
def test_raises_exception_when_over_query_limit def test_raises_exception_when_over_query_limit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment