Skip to content

Commit

Permalink
Don't specify protocol in proxy config.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreisner committed May 2, 2011
1 parent 864fff2 commit ef11425
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/geocoder/configuration.rb
Expand Up @@ -15,10 +15,10 @@ def self.options_and_defaults
# 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
Expand Down
9 changes: 5 additions & 4 deletions lib/geocoder/lookups/base.rb
Expand Up @@ -58,14 +58,15 @@ def map_link_url(coordinates)
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/geocoder_test.rb
Expand Up @@ -21,7 +21,7 @@ def test_exception_raised_on_bad_lookup_config
# --- 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
Expand Down

0 comments on commit ef11425

Please sign in to comment.