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