[前][次][番号順一覧][スレッド一覧]

ruby-changes:24437

From: naruse <ko1@a...>
Date: Sun, 22 Jul 2012 00:46:23 +0900 (JST)
Subject: [ruby-changes:24437] naruse:r36488 (trunk): * lib/net/http.rb (Net::HTTP.newobj): return back for compatibility.

naruse	2012-07-22 00:45:10 +0900 (Sun, 22 Jul 2012)

  New Revision: 36488

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36488

  Log:
    * lib/net/http.rb (Net::HTTP.newobj): return back for compatibility.
    
    * lib/net/http.rb (Net::HTTP.new): set default_port if proxy port is
      not given.
    
    * lib/net/http.rb (Net::HTTP#initialize): ditto.
    
    * lib/net/http.rb (Net::HTTP#proxy?): return true or false.
    
    * lib/net/http.rb (Net::HTTP#proxy_address): check proxy_uri is not nil.
    
    * lib/net/http.rb (Net::HTTP#proxy_port): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http.rb
    trunk/test/net/http/test_http.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36487)
+++ ChangeLog	(revision 36488)
@@ -1,3 +1,21 @@
+Sat Jul 21 06:21:45 2012  NARUSE, Yui  <naruse@r...>
+
+	* lib/net/http.rb: fixes for r36476. [Feature #6546]
+	  http://u64.rubyci.org/~chkbuild/ruby-trunk/log/20120720T030101Z.diff.html.gz
+
+	* lib/net/http.rb (Net::HTTP.newobj): return back for compatibility.
+
+	* lib/net/http.rb (Net::HTTP.new): set default_port if proxy port is
+	  not given.
+
+	* lib/net/http.rb (Net::HTTP#initialize): ditto.
+
+	* lib/net/http.rb (Net::HTTP#proxy?): return true or false.
+
+	* lib/net/http.rb (Net::HTTP#proxy_address): check proxy_uri is not nil.
+
+	* lib/net/http.rb (Net::HTTP#proxy_port): ditto.
+
 Sat Jul 21 23:12:53 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* thread_pthread.c (ruby_init_stack): STACK_GROW_DIR_DETECTION is
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 36487)
+++ lib/net/http.rb	(revision 36488)
@@ -577,6 +577,10 @@
       http.start(&block)
     end
 
+    class << HTTP
+      alias newobj new # :nodoc:
+    end
+
     # Creates a new Net::HTTP object without opening a TCP connection or
     # HTTP session.
     #
@@ -609,7 +613,7 @@
         http.proxy_from_env = true
       else
         http.proxy_address = p_addr
-        http.proxy_port    = p_port
+        http.proxy_port    = p_port || default_port
         http.proxy_user    = p_user
         http.proxy_pass    = p_pass
       end
@@ -964,7 +968,7 @@
           @proxy_port    = nil
         else
           @proxy_address = p_addr
-          @proxy_port    = p_port
+          @proxy_port    = p_port || default_port
         end
 
         @proxy_user = p_user
@@ -994,7 +998,7 @@
 
     # True if requests for this connection will be proxied
     def proxy?
-      if @proxy_from_env then
+      !!if @proxy_from_env then
         proxy_uri
       else
         @proxy_address
@@ -1014,7 +1018,7 @@
     # The address of the proxy server, if one is configured.
     def proxy_address
       if @proxy_from_env then
-        proxy_uri.hostname
+        proxy_uri && proxy_uri.hostname
       else
         @proxy_address
       end
@@ -1023,7 +1027,7 @@
     # The port of the proxy server, if one is configured.
     def proxy_port
       if @proxy_from_env then
-        proxy_uri.port
+        proxy_uri && proxy_uri.port
       else
         @proxy_port
       end
Index: test/net/http/test_http.rb
===================================================================
--- test/net/http/test_http.rb	(revision 36487)
+++ test/net/http/test_http.rb	(revision 36488)
@@ -26,6 +26,11 @@
     http = proxy_class.new 'example'
 
     refute http.proxy_from_env?
+
+
+    proxy_class = Net::HTTP.Proxy 'proxy.example'
+    assert_equal 'proxy.example', proxy_class.proxy_address
+    assert_equal 80,              proxy_class.proxy_port
   end
 
   def test_class_Proxy_from_ENV
@@ -84,8 +89,10 @@
 
   def test_proxy_address
     http = Net::HTTP.new 'example', nil, 'proxy.example'
+    assert_equal 'proxy.example', http.proxy_address
 
-    assert_equal 'proxy.example', http.proxy_address
+    http = Net::HTTP.new 'example', nil
+    assert_equal nil, http.proxy_address
   end
 
   def test_proxy_address_ENV
@@ -100,7 +107,7 @@
 
   def test_proxy_eh_no_proxy
     clean_http_proxy_env do
-      refute Net::HTTP.new('example', nil, nil).proxy?
+      assert_equal false, Net::HTTP.new('example', nil, nil).proxy?
     end
   end
 
@@ -110,13 +117,13 @@
 
       http = Net::HTTP.new 'example'
 
-      assert http.proxy?
+      assert_equal true, http.proxy?
     end
   end
 
   def test_proxy_eh_ENV_none_set
     clean_http_proxy_env do
-      refute Net::HTTP.new('example').proxy?
+      assert_equal false, Net::HTTP.new('example').proxy?
     end
   end
 
@@ -125,14 +132,18 @@
       ENV['http_proxy'] = 'http://proxy.example:8000'
       ENV['no_proxy']   = 'example'
 
-      refute Net::HTTP.new('example').proxy?
+      assert_equal false, Net::HTTP.new('example').proxy?
     end
   end
 
   def test_proxy_port
+    http = Net::HTTP.new 'exmaple', nil, 'proxy.example'
+    assert_equal 'proxy.example', http.proxy_address
+    assert_equal 80, http.proxy_port
     http = Net::HTTP.new 'exmaple', nil, 'proxy.example', 8000
-
     assert_equal 8000, http.proxy_port
+    http = Net::HTTP.new 'exmaple', nil
+    assert_equal nil, http.proxy_port
   end
 
   def test_proxy_port_ENV
@@ -145,6 +156,16 @@
     end
   end
 
+  def test_newobj
+    clean_http_proxy_env do
+      ENV['http_proxy'] = 'http://proxy.example:8000'
+
+      http = Net::HTTP.newobj 'example'
+
+      assert_equal false, http.proxy?
+    end
+  end
+
   def clean_http_proxy_env
     orig = {
       'http_proxy'      => ENV['http_proxy'],

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]