diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-21 15:45:10 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-21 15:45:10 +0000 |
commit | 07a6d0e9d112db7276492bcaf0856e04399232c1 (patch) | |
tree | cd5bda2fea60bcae2445788e7910a72a7adfed45 | |
parent | 36c45154d609e97f45ea1fca2477d9675f414616 (diff) | |
download | ruby-07a6d0e9d112db7276492bcaf0856e04399232c1.tar.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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | lib/net/http.rb | 14 | ||||
-rw-r--r-- | test/net/http/test_http.rb | 33 |
3 files changed, 54 insertions, 11 deletions
@@ -1,3 +1,21 @@ +Sat Jul 21 06:21:45 2012 NARUSE, Yui <naruse@ruby-lang.org> + + * 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@ruby-lang.org> * thread_pthread.c (ruby_init_stack): STACK_GROW_DIR_DETECTION is diff --git a/lib/net/http.rb b/lib/net/http.rb index 96e95ec3ad..5a4d553388 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -577,6 +577,10 @@ module Net #:nodoc: 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 @@ module Net #:nodoc: 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 @@ module Net #:nodoc: @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 @@ module Net #:nodoc: # 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 @@ module Net #:nodoc: # 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 @@ module Net #:nodoc: # 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 diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index df71c2add9..4867acf737 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -26,6 +26,11 @@ class TestNetHTTP < Test::Unit::TestCase 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 @@ class TestNetHTTP < Test::Unit::TestCase def test_proxy_address http = Net::HTTP.new 'example', nil, 'proxy.example' - 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 @@ class TestNetHTTP < Test::Unit::TestCase 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 @@ class TestNetHTTP < Test::Unit::TestCase 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 @@ class TestNetHTTP < Test::Unit::TestCase 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 @@ class TestNetHTTP < Test::Unit::TestCase 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'], |