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

Partially revert "Update license for OpenStreetMap (#883)."

This reverts the parts of commit 350567f5
that are outside of the README and should not have been included.
parent 350567f5
Branches
Tags
No related merge requests found
...@@ -86,6 +86,15 @@ module Geocoder ...@@ -86,6 +86,15 @@ module Geocoder
@cache @cache
end end
##
# Array containing the protocols supported by the api.
# Should be set to [:http] if only HTTP is supported
# or [:https] if only HTTPS is supported.
#
def supported_protocols
[:http, :https]
end
private # ------------------------------------------------------------- private # -------------------------------------------------------------
## ##
...@@ -99,7 +108,6 @@ module Geocoder ...@@ -99,7 +108,6 @@ module Geocoder
# Object used to make HTTP requests. # Object used to make HTTP requests.
# #
def http_client def http_client
protocol = "http#{'s' if use_ssl?}"
proxy_name = "#{protocol}_proxy" proxy_name = "#{protocol}_proxy"
if proxy = configuration.send(proxy_name) if proxy = configuration.send(proxy_name)
proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy
...@@ -183,7 +191,7 @@ module Geocoder ...@@ -183,7 +191,7 @@ module Geocoder
JSON.parse(data) JSON.parse(data)
end end
rescue => err rescue => err
raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON.") raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON: #{data}")
end end
## ##
...@@ -265,6 +273,7 @@ module Geocoder ...@@ -265,6 +273,7 @@ module Geocoder
def make_api_request(query) def make_api_request(query)
timeout(configuration.timeout) do timeout(configuration.timeout) do
uri = URI.parse(query_url(query)) uri = URI.parse(query_url(query))
Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client| http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client|
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers) req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
if configuration.basic_auth[:user] and configuration.basic_auth[:password] if configuration.basic_auth[:user] and configuration.basic_auth[:password]
...@@ -279,8 +288,14 @@ module Geocoder ...@@ -279,8 +288,14 @@ module Geocoder
end end
def use_ssl? def use_ssl?
if supported_protocols == [:https]
true
elsif supported_protocols == [:http]
false
else
configuration.use_https configuration.use_https
end end
end
def check_api_key_configuration!(query) def check_api_key_configuration!(query)
key_parts = query.lookup.required_api_key_parts key_parts = query.lookup.required_api_key_parts
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment