mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
159fa373f8
commit
c165203564
3 changed files with 35 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue