From 2b5b1f1ee53ae8c7d4af97b2cd07ece14389d56d Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@jeremyevans.net>
Date: Sat, 1 Jun 2019 20:35:40 -0700
Subject: [PATCH] Deprecate override of Kernel.open in open-uri

Ruby 2.5 announced open-uri's Kernel.open override will be deprecated
in the future.  Instead of having URI.open call Kernel.open,
Kernel.open now calls URI.open in the case where URI.open would be
used:

* first argument responds to open
* first argument is implicitly convertible to string, and is a
  parseable URI, and the URI responds to open.

One issue with this is that Pathname objects triggered the warning,
since they respond to open.  Fix that by checking if the first
argument responds to to_path, and if so, do not have Kernel.open
call URI.open.
---
 lib/open-uri.rb                |  27 +++++---
 test/open-uri/test_open-uri.rb | 110 ++++++++++++++++++---------------
 test/open-uri/test_ssl.rb      |  12 ++--
 3 files changed, 85 insertions(+), 64 deletions(-)

diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 38f074ef59..3aeed06ed4 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -10,6 +10,21 @@ class << self
     alias open_uri_original_open open # :nodoc:
   end
 
+  def open(name, *rest, &block) # :nodoc:
+    if (name.respond_to?(:open) && !name.respond_to?(:to_path)) ||
+       (name.respond_to?(:to_str) &&
+        %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
+        (uri = URI.parse(name)).respond_to?(:open))
+      warn('calling URI.open via Kernel#open is deprecated, call URI.open directly', uplevel: 1)
+      URI.open(name, *rest, &block)
+    else
+      open_uri_original_open(name, *rest, &block)
+    end
+  end
+  module_function :open
+end
+
+module URI
   # Allows the opening of various resources including URIs.
   #
   # If the first argument responds to the 'open' method, 'open' is called on
@@ -26,7 +41,7 @@ class << self
   #
   # We can accept URIs and strings that begin with http://, https:// and
   # ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
-  def open(name, *rest, &block) # :doc:
+  def self.open(name, *rest, &block)
     if name.respond_to?(:open)
       name.open(*rest, &block)
     elsif name.respond_to?(:to_str) &&
@@ -35,16 +50,10 @@ def open(name, *rest, &block) # :doc:
       uri.open(*rest, &block)
     else
       open_uri_original_open(name, *rest, &block)
+      # After Kernel#open override is removed:
+      #super
     end
   end
-  module_function :open
-end
-
-module URI #:nodoc:
-  # alias for Kernel.open defined in open-uri.
-  def self.open(name, *rest, &block)
-    Kernel.open(name, *rest, &block)
-  end
 end
 
 # OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb
index 0301483902..39cf4201a2 100644
--- a/test/open-uri/test_open-uri.rb
+++ b/test/open-uri/test_open-uri.rb
@@ -68,6 +68,18 @@ def teardown
     @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] }
   end
 
+  def test_deprecated_kernel_open
+    with_http {|srv, dr, url|
+      srv.mount_proc("/foo200", lambda { |req, res| res.body = "foo200" } )
+      assert_warning(/calling URI.open via Kernel#open is deprecated, call URI.open directly/) {
+        open("#{url}/foo200") {|f|
+          assert_equal("200", f.status[0])
+          assert_equal("foo200", f.read)
+        }
+      }
+    }
+  end
+
   def test_200_uri_open
     with_http {|srv, dr, url|
       srv.mount_proc("/urifoo200", lambda { |req, res| res.body = "urifoo200" } )
@@ -81,7 +93,7 @@ def test_200_uri_open
   def test_200
     with_http {|srv, dr, url|
       srv.mount_proc("/foo200", lambda { |req, res| res.body = "foo200" } )
-      open("#{url}/foo200") {|f|
+      URI.open("#{url}/foo200") {|f|
         assert_equal("200", f.status[0])
         assert_equal("foo200", f.read)
       }
@@ -92,7 +104,7 @@ def test_200big
     with_http {|srv, dr, url|
       content = "foo200big"*10240
       srv.mount_proc("/foo200big", lambda { |req, res| res.body = content } )
-      open("#{url}/foo200big") {|f|
+      URI.open("#{url}/foo200big") {|f|
         assert_equal("200", f.status[0])
         assert_equal(content, f.read)
       }
@@ -105,7 +117,7 @@ def test_404
       assert_match(%r{ERROR `/not-exist' not found}, server_log[0])
     }
     with_http(log_tester) {|srv, dr, url, server_thread, server_log|
-      exc = assert_raise(OpenURI::HTTPError) { open("#{url}/not-exist") {} }
+      exc = assert_raise(OpenURI::HTTPError) { URI.open("#{url}/not-exist") {} }
       assert_equal("404", exc.io.status[0])
     }
   end
@@ -114,7 +126,7 @@ def test_open_uri
     with_http {|srv, dr, url|
       srv.mount_proc("/foo_ou", lambda { |req, res| res.body = "foo_ou" } )
       u = URI("#{url}/foo_ou")
-      open(u) {|f|
+      URI.open(u) {|f|
         assert_equal("200", f.status[0])
         assert_equal("foo_ou", f.read)
       }
@@ -122,7 +134,7 @@ def test_open_uri
   end
 
   def test_open_too_many_arg
-    assert_raise(ArgumentError) { open("http://192.0.2.1/tma", "r", 0666, :extra) {} }
+    assert_raise(ArgumentError) { URI.open("http://192.0.2.1/tma", "r", 0666, :extra) {} }
   end
 
   def test_read_timeout
@@ -169,28 +181,28 @@ def test_open_timeout
   end
 
   def test_invalid_option
-    assert_raise(ArgumentError) { open("http://127.0.0.1/", :invalid_option=>true) {} }
+    assert_raise(ArgumentError) { URI.open("http://127.0.0.1/", :invalid_option=>true) {} }
   end
 
   def test_mode
     with_http {|srv, dr, url|
       srv.mount_proc("/mode", lambda { |req, res| res.body = "mode" } )
-      open("#{url}/mode", "r") {|f|
+      URI.open("#{url}/mode", "r") {|f|
         assert_equal("200", f.status[0])
         assert_equal("mode", f.read)
       }
-      open("#{url}/mode", "r", 0600) {|f|
+      URI.open("#{url}/mode", "r", 0600) {|f|
         assert_equal("200", f.status[0])
         assert_equal("mode", f.read)
       }
-      assert_raise(ArgumentError) { open("#{url}/mode", "a") {} }
-      open("#{url}/mode", "r:us-ascii") {|f|
+      assert_raise(ArgumentError) { URI.open("#{url}/mode", "a") {} }
+      URI.open("#{url}/mode", "r:us-ascii") {|f|
         assert_equal(Encoding::US_ASCII, f.read.encoding)
       }
-      open("#{url}/mode", "r:utf-8") {|f|
+      URI.open("#{url}/mode", "r:utf-8") {|f|
         assert_equal(Encoding::UTF_8, f.read.encoding)
       }
-      assert_raise(ArgumentError) { open("#{url}/mode", "r:invalid-encoding") {} }
+      assert_raise(ArgumentError) { URI.open("#{url}/mode", "r:invalid-encoding") {} }
     }
   end
 
@@ -198,7 +210,7 @@ def test_without_block
     with_http {|srv, dr, url|
       srv.mount_proc("/without_block", lambda { |req, res| res.body = "without_block" } )
       begin
-        f = open("#{url}/without_block")
+        f = URI.open("#{url}/without_block")
         assert_equal("200", f.status[0])
         assert_equal("without_block", f.read)
       ensure
@@ -211,7 +223,7 @@ def test_close_in_block_small
     with_http {|srv, dr, url|
       srv.mount_proc("/close200", lambda { |req, res| res.body = "close200" } )
       assert_nothing_raised {
-        open("#{url}/close200") {|f|
+        URI.open("#{url}/close200") {|f|
           f.close
         }
       }
@@ -223,7 +235,7 @@ def test_close_in_block_big
       content = "close200big"*10240
       srv.mount_proc("/close200big", lambda { |req, res| res.body = content } )
       assert_nothing_raised {
-        open("#{url}/close200big") {|f|
+        URI.open("#{url}/close200big") {|f|
           f.close
         }
       }
@@ -235,7 +247,7 @@ def test_header
     myheader2 = nil
     with_http {|srv, dr, url|
       srv.mount_proc("/h/") {|req, res| myheader2 = req['myheader']; res.body = "foo" }
-      open("#{url}/h/", 'MyHeader'=>myheader1) {|f|
+      URI.open("#{url}/h/", 'MyHeader'=>myheader1) {|f|
         assert_equal("foo", f.read)
         assert_equal(myheader1, myheader2)
       }
@@ -244,13 +256,13 @@ def test_header
 
   def test_multi_proxy_opt
     assert_raise(ArgumentError) {
-      open("http://127.0.0.1/", :proxy_http_basic_authentication=>true, :proxy=>true) {}
+      URI.open("http://127.0.0.1/", :proxy_http_basic_authentication=>true, :proxy=>true) {}
     }
   end
 
   def test_non_http_proxy
     assert_raise(RuntimeError) {
-      open("http://127.0.0.1/", :proxy=>URI("ftp://127.0.0.1/")) {}
+      URI.open("http://127.0.0.1/", :proxy=>URI("ftp://127.0.0.1/")) {}
     }
   end
 
@@ -273,28 +285,28 @@ def test_proxy
       begin
         proxy_thread = proxy.start
         srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
-        open("#{url}/proxy", :proxy=>proxy_url) {|f|
+        URI.open("#{url}/proxy", :proxy=>proxy_url) {|f|
           assert_equal("200", f.status[0])
           assert_equal("proxy", f.read)
         }
         assert_match(/#{Regexp.quote url}/, proxy_auth_log); proxy_auth_log.clear
-        open("#{url}/proxy", :proxy=>URI(proxy_url)) {|f|
+        URI.open("#{url}/proxy", :proxy=>URI(proxy_url)) {|f|
           assert_equal("200", f.status[0])
           assert_equal("proxy", f.read)
         }
         assert_match(/#{Regexp.quote url}/, proxy_auth_log); proxy_auth_log.clear
-        open("#{url}/proxy", :proxy=>nil) {|f|
+        URI.open("#{url}/proxy", :proxy=>nil) {|f|
           assert_equal("200", f.status[0])
           assert_equal("proxy", f.read)
         }
         assert_equal("", proxy_auth_log); proxy_auth_log.clear
         assert_raise(ArgumentError) {
-          open("#{url}/proxy", :proxy=>:invalid) {}
+          URI.open("#{url}/proxy", :proxy=>:invalid) {}
         }
         assert_equal("", proxy_auth_log); proxy_auth_log.clear
         with_env("http_proxy"=>proxy_url) {
           # should not use proxy for 127.0.0.0/8.
-          open("#{url}/proxy") {|f|
+          URI.open("#{url}/proxy") {|f|
             assert_equal("200", f.status[0])
             assert_equal("proxy", f.read)
           }
@@ -330,7 +342,7 @@ def test_proxy_http_basic_authentication_failure
       begin
         th = proxy.start
         srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
-        exc = assert_raise(OpenURI::HTTPError) { open("#{url}/proxy", :proxy=>proxy_url) {} }
+        exc = assert_raise(OpenURI::HTTPError) { URI.open("#{url}/proxy", :proxy=>proxy_url) {} }
         assert_equal("407", exc.io.status[0])
         assert_match(/#{Regexp.quote url}/, proxy_auth_log); proxy_auth_log.clear
       ensure
@@ -363,14 +375,14 @@ def test_proxy_http_basic_authentication_success
       begin
         th = proxy.start
         srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
-        open("#{url}/proxy",
+        URI.open("#{url}/proxy",
             :proxy_http_basic_authentication=>[proxy_url, "user", "pass"]) {|f|
           assert_equal("200", f.status[0])
           assert_equal("proxy", f.read)
         }
         assert_match(/#{Regexp.quote url}/, proxy_auth_log); proxy_auth_log.clear
         assert_raise(ArgumentError) {
-          open("#{url}/proxy",
+          URI.open("#{url}/proxy",
               :proxy_http_basic_authentication=>[true, "user", "pass"]) {}
         }
         assert_equal("", proxy_auth_log); proxy_auth_log.clear
@@ -404,7 +416,7 @@ def test_authenticated_proxy_http_basic_authentication_success
       begin
         th = proxy.start
         srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
-        open("#{url}/proxy", :proxy => proxy_url) {|f|
+        URI.open("#{url}/proxy", :proxy => proxy_url) {|f|
           assert_equal("200", f.status[0])
           assert_equal("proxy", f.read)
         }
@@ -423,12 +435,12 @@ def test_redirect
       srv.mount_proc("/r1/") {|req, res| res.status = 301; res["location"] = "#{url}/r2"; res.body = "r1" }
       srv.mount_proc("/r2/") {|req, res| res.body = "r2" }
       srv.mount_proc("/to-file/") {|req, res| res.status = 301; res["location"] = "file:///foo" }
-      open("#{url}/r1/") {|f|
+      URI.open("#{url}/r1/") {|f|
         assert_equal("#{url}/r2", f.base_uri.to_s)
         assert_equal("r2", f.read)
       }
-      assert_raise(OpenURI::HTTPRedirect) { open("#{url}/r1/", :redirect=>false) {} }
-      assert_raise(RuntimeError) { open("#{url}/to-file/") {} }
+      assert_raise(OpenURI::HTTPRedirect) { URI.open("#{url}/r1/", :redirect=>false) {} }
+      assert_raise(RuntimeError) { URI.open("#{url}/to-file/") {} }
     }
   end
 
@@ -436,7 +448,7 @@ def test_redirect_loop
     with_http {|srv, dr, url|
       srv.mount_proc("/r1/") {|req, res| res.status = 301; res["location"] = "#{url}/r2"; res.body = "r1" }
       srv.mount_proc("/r2/") {|req, res| res.status = 301; res["location"] = "#{url}/r1"; res.body = "r2" }
-      assert_raise(RuntimeError) { open("#{url}/r1/") {} }
+      assert_raise(RuntimeError) { URI.open("#{url}/r1/") {} }
     }
   end
 
@@ -515,7 +527,7 @@ def setup_redirect_auth(srv, url)
   def test_redirect_auth_success
     with_http {|srv, dr, url|
       setup_redirect_auth(srv, url)
-      open("#{url}/r2/", :http_basic_authentication=>['user', 'pass']) {|f|
+      URI.open("#{url}/r2/", :http_basic_authentication=>['user', 'pass']) {|f|
         assert_equal("r2", f.read)
       }
     }
@@ -528,7 +540,7 @@ def test_redirect_auth_failure_r2
     }
     with_http(log_tester) {|srv, dr, url, server_thread, server_log|
       setup_redirect_auth(srv, url)
-      exc = assert_raise(OpenURI::HTTPError) { open("#{url}/r2/") {} }
+      exc = assert_raise(OpenURI::HTTPError) { URI.open("#{url}/r2/") {} }
       assert_equal("401", exc.io.status[0])
     }
   end
@@ -540,13 +552,13 @@ def test_redirect_auth_failure_r1
     }
     with_http(log_tester) {|srv, dr, url, server_thread, server_log|
       setup_redirect_auth(srv, url)
-      exc = assert_raise(OpenURI::HTTPError) { open("#{url}/r1/", :http_basic_authentication=>['user', 'pass']) {} }
+      exc = assert_raise(OpenURI::HTTPError) { URI.open("#{url}/r1/", :http_basic_authentication=>['user', 'pass']) {} }
       assert_equal("401", exc.io.status[0])
     }
   end
 
   def test_userinfo
-    assert_raise(ArgumentError) { open("http://user:pass@127.0.0.1/") {} }
+    assert_raise(ArgumentError) { URI.open("http://user:pass@127.0.0.1/") {} }
   end
 
   def test_progress
@@ -555,7 +567,7 @@ def test_progress
       srv.mount_proc("/data/") {|req, res| res.body = content }
       length = []
       progress = []
-      open("#{url}/data/",
+      URI.open("#{url}/data/",
            :content_length_proc => lambda {|n| length << n },
            :progress_proc => lambda {|n| progress << n }
           ) {|f|
@@ -575,7 +587,7 @@ def test_progress_chunked
       srv.mount_proc("/data/") {|req, res| res.body = content; res.chunked = true }
       length = []
       progress = []
-      open("#{url}/data/",
+      URI.open("#{url}/data/",
            :content_length_proc => lambda {|n| length << n },
            :progress_proc => lambda {|n| progress << n }
           ) {|f|
@@ -605,25 +617,25 @@ def test_encoding
       srv.mount_proc("/u8/") {|req, res| res.body = content_u8; res['content-type'] = 'text/plain; charset=utf-8' }
       srv.mount_proc("/ej/") {|req, res| res.body = content_ej; res['content-type'] = 'TEXT/PLAIN; charset=EUC-JP' }
       srv.mount_proc("/nc/") {|req, res| res.body = "aa"; res['content-type'] = 'Text/Plain' }
-      open("#{url}/u8/") {|f|
+      URI.open("#{url}/u8/") {|f|
         assert_equal(content_u8, f.read)
         assert_equal("text/plain", f.content_type)
         assert_equal("utf-8", f.charset)
       }
-      open("#{url}/ej/") {|f|
+      URI.open("#{url}/ej/") {|f|
         assert_equal(content_ej, f.read)
         assert_equal("text/plain", f.content_type)
         assert_equal("euc-jp", f.charset)
         assert_equal(Encoding::EUC_JP, f.read.encoding)
       }
-      open("#{url}/ej/", 'r:utf-8') {|f|
+      URI.open("#{url}/ej/", 'r:utf-8') {|f|
         # override charset with encoding option
         assert_equal(content_ej.dup.force_encoding('utf-8'), f.read)
         assert_equal("text/plain", f.content_type)
         assert_equal("euc-jp", f.charset)
         assert_equal(Encoding::UTF_8, f.read.encoding)
       }
-      open("#{url}/ej/", :encoding=>'utf-8') {|f|
+      URI.open("#{url}/ej/", :encoding=>'utf-8') {|f|
         # override charset with encoding option
         assert_equal(content_ej.dup.force_encoding('utf-8'), f.read)
         assert_equal("text/plain", f.content_type)
@@ -631,9 +643,9 @@ def test_encoding
         assert_equal(Encoding::UTF_8, f.read.encoding)
       }
       assert_raise(ArgumentError) {
-        open("#{url}/ej/", 'r:utf-8', :encoding=>'utf-8') {|f| }
+        URI.open("#{url}/ej/", 'r:utf-8', :encoding=>'utf-8') {|f| }
       }
-      open("#{url}/nc/") {|f|
+      URI.open("#{url}/nc/") {|f|
         assert_equal("aa", f.read)
         assert_equal("text/plain", f.content_type)
         assert_equal("iso-8859-1", f.charset)
@@ -646,7 +658,7 @@ def test_quoted_attvalue
     with_http {|srv, dr, url|
       content_u8 = "\u3042"
       srv.mount_proc("/qu8/") {|req, res| res.body = content_u8; res['content-type'] = 'text/plain; charset="utf\-8"' }
-      open("#{url}/qu8/") {|f|
+      URI.open("#{url}/qu8/") {|f|
         assert_equal(content_u8, f.read)
         assert_equal("text/plain", f.content_type)
         assert_equal("utf-8", f.charset)
@@ -657,7 +669,7 @@ def test_quoted_attvalue
   def test_last_modified
     with_http {|srv, dr, url|
       srv.mount_proc("/data/") {|req, res| res.body = "foo"; res['last-modified'] = 'Fri, 07 Aug 2009 06:05:04 GMT' }
-      open("#{url}/data/") {|f|
+      URI.open("#{url}/data/") {|f|
         assert_equal("foo", f.read)
         assert_equal(Time.utc(2009,8,7,6,5,4), f.last_modified)
       }
@@ -671,15 +683,15 @@ def test_content_encoding
       srv.mount_proc("/data/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip' }
       srv.mount_proc("/data2/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip'; res.chunked = true }
       srv.mount_proc("/noce/") {|req, res| res.body = content_gz }
-      open("#{url}/data/") {|f|
+      URI.open("#{url}/data/") {|f|
         assert_equal [], f.content_encoding
         assert_equal(content, f.read)
       }
-      open("#{url}/data2/") {|f|
+      URI.open("#{url}/data2/") {|f|
         assert_equal [], f.content_encoding
         assert_equal(content, f.read)
       }
-      open("#{url}/noce/") {|f|
+      URI.open("#{url}/noce/") {|f|
         assert_equal [], f.content_encoding
         assert_equal(content_gz, f.read.force_encoding("ascii-8bit"))
       }
@@ -693,7 +705,7 @@ def test_multiple_cookies
         res.cookies << "name2=value2; blabla"
         res.body = "foo"
       }
-      open("#{url}/mcookie/") {|f|
+      URI.open("#{url}/mcookie/") {|f|
         assert_equal("foo", f.read)
         assert_equal(["name1=value1; blabla", "name2=value2; blabla"],
                      f.metas['set-cookie'].sort)
diff --git a/test/open-uri/test_ssl.rb b/test/open-uri/test_ssl.rb
index 337139604f..4f645d83b9 100644
--- a/test/open-uri/test_ssl.rb
+++ b/test/open-uri/test_ssl.rb
@@ -67,7 +67,7 @@ def teardown
 
   def setup_validation(srv, dr)
     cacert_filename = "#{dr}/cacert.pem"
-    open(cacert_filename, "w") {|f| f << CA_CERT }
+    URI.open(cacert_filename, "w") {|f| f << CA_CERT }
     srv.mount_proc("/data", lambda { |req, res| res.body = "ddd" } )
     cacert_filename
   end
@@ -75,7 +75,7 @@ def setup_validation(srv, dr)
   def test_validation_success
     with_https {|srv, dr, url|
       cacert_filename = setup_validation(srv, dr)
-      open("#{url}/data", :ssl_ca_cert => cacert_filename) {|f|
+      URI.open("#{url}/data", :ssl_ca_cert => cacert_filename) {|f|
         assert_equal("200", f.status[0])
         assert_equal("ddd", f.read)
       }
@@ -85,7 +85,7 @@ def test_validation_success
   def test_validation_noverify
     with_https {|srv, dr, url|
       setup_validation(srv, dr)
-      open("#{url}/data", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) {|f|
+      URI.open("#{url}/data", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) {|f|
         assert_equal("200", f.status[0])
         assert_equal("ddd", f.read)
       }
@@ -103,7 +103,7 @@ def test_validation_failure
     end
     with_https(log_tester) {|srv, dr, url, server_thread, server_log|
       setup_validation(srv, dr)
-      assert_raise(OpenSSL::SSL::SSLError) { open("#{url}/data") {} }
+      assert_raise(OpenSSL::SSL::SSLError) { URI.open("#{url}/data") {} }
     }
   end
 
@@ -149,7 +149,7 @@ def test_proxy_cacert_file
     }
     with_https_proxy(proxy_log_tester) {|srv, dr, url_, cacert_filename, cacert_directory, proxy_host, proxy_port|
       url = url_
-      open("#{url}/proxy", :proxy=>"http://#{proxy_host}:#{proxy_port}/", :ssl_ca_cert => cacert_filename) {|f|
+      URI.open("#{url}/proxy", :proxy=>"http://#{proxy_host}:#{proxy_port}/", :ssl_ca_cert => cacert_filename) {|f|
         assert_equal("200", f.status[0])
         assert_equal("proxy", f.read)
       }
@@ -165,7 +165,7 @@ def test_proxy_cacert_dir
     }
     with_https_proxy(proxy_log_tester) {|srv, dr, url_, cacert_filename, cacert_directory, proxy_host, proxy_port|
       url = url_
-      open("#{url}/proxy", :proxy=>"http://#{proxy_host}:#{proxy_port}/", :ssl_ca_cert => cacert_directory) {|f|
+      URI.open("#{url}/proxy", :proxy=>"http://#{proxy_host}:#{proxy_port}/", :ssl_ca_cert => cacert_directory) {|f|
         assert_equal("200", f.status[0])
         assert_equal("proxy", f.read)
       }
-- 
2.21.0

