From 6d0e846cfd3aadae1aa2f0a692be69edc73a5615 Mon Sep 17 00:00:00 2001
From: Tim Williams <tim@teachmatic.com>
Date: Wed, 23 Oct 2013 14:17:16 +0100
Subject: [PATCH] Allow proxy settings to include protocol

http_proxy & https_proxy settings can now be specified with or without
the protocol prefix.
---
 lib/geocoder/lookups/base.rb |  2 +-
 test/proxy_test.rb           | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb
index bc4703a2..014abe2d 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 654b8160..71f60109 100644
--- a/test/proxy_test.rb
+++ b/test/proxy_test.rb
@@ -20,4 +20,16 @@ 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(:http_proxy => 'https://localhost')
+    lookup = Geocoder::Lookup::Google.new
+    assert lookup.send(:http_client).proxy_class?
+  end
 end
-- 
GitLab