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
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Wed Aug 6 03:17:34 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Wed Aug 6 02:16:43 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/http/generic_request.rb
|
* lib/net/http/generic_request.rb
|
||||||
|
|
|
@ -1455,10 +1455,7 @@ module Net #:nodoc:
|
||||||
req['connection'] ||= 'close'
|
req['connection'] ||= 'close'
|
||||||
end
|
end
|
||||||
|
|
||||||
host = req['host'] || address
|
req.update_uri address, port, use_ssl?
|
||||||
host = $1 if host =~ /(.*):\d+$/
|
|
||||||
req.update_uri host, port, use_ssl?
|
|
||||||
|
|
||||||
req['host'] ||= addr_port()
|
req['host'] ||= addr_port()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -136,21 +136,34 @@ class Net::HTTPGenericRequest
|
||||||
end
|
end
|
||||||
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
|
return unless @uri
|
||||||
|
|
||||||
@uri.host ||= host
|
if ssl
|
||||||
@uri.port = port
|
scheme = 'https'.freeze
|
||||||
|
klass = URI::HTTPS
|
||||||
scheme = ssl ? 'https' : 'http'
|
else
|
||||||
|
scheme = 'http'.freeze
|
||||||
# convert the class of the URI
|
klass = URI::HTTP
|
||||||
unless scheme == @uri.scheme then
|
|
||||||
new_uri = @uri.to_s.sub(/^https?/, scheme)
|
|
||||||
@uri = URI new_uri
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue