summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-05 19:10:05 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-05 19:10:05 +0000
commitc1652035644c5f52cd91cfb264df5072445f4020 (patch)
tree4380446ef46174c9a75842bdfe0505102dec4894 /lib
parent159fa373f8e913a5464ab88c308e4375c946af8b (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http.rb5
-rw-r--r--lib/net/http/generic_request.rb33
2 files changed, 24 insertions, 14 deletions
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'
+ 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