diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index bc4703a275459b5501da5f43d7fc8a25d5c3969d..014abe2d37882fe56e5e83be2f929cb3d080aee9 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -99,7 +99,7 @@ module Geocoder protocol = "http#{'s' if configuration.use_https}" proxy_name = "#{protocol}_proxy" if proxy = configuration.send(proxy_name) - proxy_url = protocol + '://' + proxy + proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy begin uri = URI.parse(proxy_url) rescue URI::InvalidURIError diff --git a/test/proxy_test.rb b/test/proxy_test.rb index 654b8160c0dd8c89fb3affbda21a8bebc423aedd..8460ee49ed464f4c8c16ce4500a58e35e8b05bf9 100644 --- a/test/proxy_test.rb +++ b/test/proxy_test.rb @@ -20,4 +20,17 @@ class ProxyTest < Test::Unit::TestCase Geocoder::Lookup::Google.new.send(:http_client) end end + + def test_accepts_proxy_with_http_protocol + Geocoder.configure(:http_proxy => 'http://localhost') + lookup = Geocoder::Lookup::Google.new + assert lookup.send(:http_client).proxy_class? + end + + def test_accepts_proxy_with_https_protocol + Geocoder.configure(:https_proxy => 'https://localhost') + Geocoder.configure(:use_https => true) + lookup = Geocoder::Lookup::Google.new + assert lookup.send(:http_client).proxy_class? + end end