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

ruby-changes:48341

From: naruse <ko1@a...>
Date: Fri, 27 Oct 2017 00:29:40 +0900 (JST)
Subject: [ruby-changes:48341] naruse:r60455 (trunk): Host header should add branckets to IPv6 address [Bug #12642]

naruse	2017-10-27 00:29:36 +0900 (Fri, 27 Oct 2017)

  New Revision: 60455

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60455

  Log:
    Host header should add branckets to IPv6 address [Bug #12642]

  Modified files:
    trunk/lib/net/http.rb
    trunk/test/net/http/test_http.rb
Index: test/net/http/test_http.rb
===================================================================
--- test/net/http/test_http.rb	(revision 60454)
+++ test/net/http/test_http.rb	(revision 60455)
@@ -59,6 +59,33 @@ class TestNetHTTP < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_http.rb#L59
     end
   end
 
+  def test_addr_port
+    http = Net::HTTP.new 'hostname.example', nil, nil
+    addr_port = http.__send__ :addr_port
+    assert_equal 'hostname.example', addr_port
+
+    http.use_ssl = true
+    addr_port = http.__send__ :addr_port
+    assert_equal 'hostname.example:80', addr_port
+
+    http = Net::HTTP.new '203.0.113.1', nil, nil
+    addr_port = http.__send__ :addr_port
+    assert_equal '203.0.113.1', addr_port
+
+    http.use_ssl = true
+    addr_port = http.__send__ :addr_port
+    assert_equal '203.0.113.1:80', addr_port
+
+    http = Net::HTTP.new '2001:db8::1', nil, nil
+    addr_port = http.__send__ :addr_port
+    assert_equal '[2001:db8::1]', addr_port
+
+    http.use_ssl = true
+    addr_port = http.__send__ :addr_port
+    assert_equal '[2001:db8::1]:80', addr_port
+
+  end
+
   def test_edit_path
     http = Net::HTTP.new 'hostname.example', nil, nil
 
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 60454)
+++ lib/net/http.rb	(revision 60455)
@@ -1612,11 +1612,10 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1612
     private
 
     def addr_port
-      if use_ssl?
-        address() + (port == HTTP.https_default_port ? '' : ":#{port()}")
-      else
-        address() + (port == HTTP.http_default_port ? '' : ":#{port()}")
-      end
+      addr = address
+      addr = "[#{addr}]" if addr.include?(":")
+      default_port = use_ssl? ? HTTP.https_default_port : HTTP.http_default_port
+      default_port == port ? addr : "#{addr}:#{port}"
     end
 
     def D(msg)

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

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