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

ruby-changes:34994

From: naruse <ko1@a...>
Date: Wed, 6 Aug 2014 04:10:14 +0900 (JST)
Subject: [ruby-changes:34994] naruse:r47076 (trunk): * lib/net/http/generic_request.rb

naruse	2014-08-06 04:10:05 +0900 (Wed, 06 Aug 2014)

  New Revision: 47076

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

  Log:
    * lib/net/http/generic_request.rb
      (Net::HTTP::GenericRequest#update_uri):
      handle scheme, host, and port to reflect connection to @uri.
    
    * lib/net/http.rb (Net::HTTP#begin_transport): move trivial handling
      to Net::HTTP::GenericRequest#update_uri.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http/generic_request.rb
    trunk/lib/net/http.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47075)
+++ ChangeLog	(revision 47076)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug  6 03:17:34 2014  NARUSE, Yui  <naruse@r...>
+
+	* lib/net/http/generic_request.rb
+	  (Net::HTTP::GenericRequest#update_uri):
+	  handle scheme, host, and port to reflect connection to @uri.
+
+	* lib/net/http.rb (Net::HTTP#begin_transport): move trivial handling
+	  to Net::HTTP::GenericRequest#update_uri.
+
+
 Wed Aug  6 02:16:43 2014  NARUSE, Yui  <naruse@r...>
 
 	* lib/net/http/generic_request.rb
Index: lib/net/http/generic_request.rb
===================================================================
--- lib/net/http/generic_request.rb	(revision 47075)
+++ lib/net/http/generic_request.rb	(revision 47076)
@@ -136,21 +136,34 @@ class Net::HTTPGenericRequest https://github.com/ruby/ruby/blob/trunk/lib/net/http/generic_request.rb#L136
     end
   end
 
-  def update_uri(host, port, ssl) # :nodoc: internal use only
+  def update_uri(addr, port, ssl) # :nodoc: internal use only
+    # reflect the connection and @path to @uri
     return unless @uri
 
-    @uri.host ||= host
-    @uri.port = port
-
-    scheme = ssl ? 'https' : 'http'
+    if ssl
+      scheme = 'https'.freeze
+      klass = URI::HTTPS
+    else
+      scheme = 'http'.freeze
+      klass = URI::HTTP
+    end
 
+    if host = @uri.host
+    elsif host = self['host']
+      host.sub!(/:.*/s, ''.freeze)
+    else
+     host = addr
+    end
     # convert the class of the URI
-    unless scheme == @uri.scheme then
-      new_uri = @uri.to_s.sub(/^https?/, scheme)
-      @uri = URI new_uri
+    if @uri.is_a?(klass)
+      @uri.host = host
+      @uri.port = port
+    else
+      @uri = klass.new(
+        scheme, @uri.userinfo,
+        host, port, nil,
+        @uri.path, nil, @uri.query, nil)
     end
-
-    @uri
   end
 
   private
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 47075)
+++ lib/net/http.rb	(revision 47076)
@@ -1455,10 +1455,7 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1455
         req['connection'] ||= 'close'
       end
 
-      host = req['host'] || address
-      host = $1 if host =~ /(.*):\d+$/
-      req.update_uri host, port, use_ssl?
-
+      req.update_uri address, port, use_ssl?
       req['host'] ||= addr_port()
     end
 

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

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