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

Don't specify protocol in proxy config.

parent 864fff29
No related branches found
No related tags found
No related merge requests found
...@@ -15,10 +15,10 @@ module Geocoder ...@@ -15,10 +15,10 @@ module Geocoder
# use HTTPS for lookup requests? (if supported) # use HTTPS for lookup requests? (if supported)
[:use_https, false], [:use_https, false],
# URL of HTTP proxy # HTTP proxy server (not including "http://")
[:http_proxy, nil], [:http_proxy, nil],
# URL of HTTPS proxy # HTTPS proxy server (not including "https://")
[:https_proxy, nil], [:https_proxy, nil],
# API key for geocoding service # API key for geocoding service
......
...@@ -58,14 +58,15 @@ module Geocoder ...@@ -58,14 +58,15 @@ module Geocoder
# Object used to make HTTP requests. # Object used to make HTTP requests.
# #
def http_client def http_client
secure = Geocoder::Configuration.use_https protocol = "http#{'s' if Geocoder::Configuration.use_https}"
proxy_name = "http#{'s' if secure}_proxy" proxy_name = "#{protocol}_proxy"
if proxy_url = Geocoder::Configuration.send(proxy_name) if proxy = Geocoder::Configuration.send(proxy_name)
proxy_url = protocol + '://' + proxy
begin begin
uri = URI.parse(proxy_url) uri = URI.parse(proxy_url)
rescue URI::InvalidURIError rescue URI::InvalidURIError
raise ConfigurationError, raise ConfigurationError,
"Error parsing HTTP#{'S' if secure} proxy URL: '#{proxy_url}'" "Error parsing #{protocol.upcase} proxy URL: '#{proxy_url}'"
end end
Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password) Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password)
else else
......
...@@ -21,7 +21,7 @@ class GeocoderTest < Test::Unit::TestCase ...@@ -21,7 +21,7 @@ class GeocoderTest < Test::Unit::TestCase
# --- sanity checks --- # --- sanity checks ---
def test_uses_proxy_when_specified def test_uses_proxy_when_specified
Geocoder::Configuration.http_proxy = 'http://localhost' Geocoder::Configuration.http_proxy = 'localhost'
lookup = Geocoder::Lookup::Google.new lookup = Geocoder::Lookup::Google.new
assert lookup.send(:http_client).proxy_class? assert lookup.send(:http_client).proxy_class?
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