Skip to content

Commit

Permalink
* lib/net/http/generic_request.rb
Browse files Browse the repository at this point in the history
  (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
  • Loading branch information
nurse committed Aug 5, 2014
1 parent 159fa37 commit c165203
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
10 changes: 10 additions & 0 deletions 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>

* lib/net/http/generic_request.rb
Expand Down
5 changes: 1 addition & 4 deletions lib/net/http.rb
Expand Up @@ -1455,10 +1455,7 @@ def begin_transport(req)
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

Expand Down
33 changes: 23 additions & 10 deletions lib/net/http/generic_request.rb
Expand Up @@ -136,21 +136,34 @@ def exec(sock, ver, path) #:nodoc: internal use only
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
Expand Down

0 comments on commit c165203

Please sign in to comment.