diff --git a/ChangeLog b/ChangeLog index e888316216..4ae9a5b2bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Aug 6 03:17:34 2014 NARUSE, Yui + + * 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 * lib/net/http/generic_request.rb diff --git a/lib/net/http.rb b/lib/net/http.rb index efa7313b40..eaf2cf4add 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1455,10 +1455,7 @@ module Net #:nodoc: 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 diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb index 0b70630d89..f410d5838e 100644 --- a/lib/net/http/generic_request.rb +++ b/lib/net/http/generic_request.rb @@ -136,21 +136,34 @@ class Net::HTTPGenericRequest 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' - - # convert the class of the URI - unless scheme == @uri.scheme then - new_uri = @uri.to_s.sub(/^https?/, scheme) - @uri = URI new_uri + if ssl + scheme = 'https'.freeze + klass = URI::HTTPS + else + scheme = 'http'.freeze + klass = URI::HTTP end - @uri + if host = @uri.host + elsif host = self['host'] + host.sub!(/:.*/s, ''.freeze) + else + host = addr + end + # convert the class of the 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 end private