Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c165203

Browse files
committed
* 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
1 parent 159fa37 commit c165203

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Wed Aug 6 03:17:34 2014 NARUSE, Yui <[email protected]>
2+
3+
* lib/net/http/generic_request.rb
4+
(Net::HTTP::GenericRequest#update_uri):
5+
handle scheme, host, and port to reflect connection to @uri.
6+
7+
* lib/net/http.rb (Net::HTTP#begin_transport): move trivial handling
8+
to Net::HTTP::GenericRequest#update_uri.
9+
10+
111
Wed Aug 6 02:16:43 2014 NARUSE, Yui <[email protected]>
212

313
* lib/net/http/generic_request.rb

lib/net/http.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,7 @@ def begin_transport(req)
14551455
req['connection'] ||= 'close'
14561456
end
14571457

1458-
host = req['host'] || address
1459-
host = $1 if host =~ /(.*):\d+$/
1460-
req.update_uri host, port, use_ssl?
1461-
1458+
req.update_uri address, port, use_ssl?
14621459
req['host'] ||= addr_port()
14631460
end
14641461

lib/net/http/generic_request.rb

+23-10
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,34 @@ def exec(sock, ver, path) #:nodoc: internal use only
136136
end
137137
end
138138

139-
def update_uri(host, port, ssl) # :nodoc: internal use only
139+
def update_uri(addr, port, ssl) # :nodoc: internal use only
140+
# reflect the connection and @path to @uri
140141
return unless @uri
141142

142-
@uri.host ||= host
143-
@uri.port = port
144-
145-
scheme = ssl ? 'https' : 'http'
143+
if ssl
144+
scheme = 'https'.freeze
145+
klass = URI::HTTPS
146+
else
147+
scheme = 'http'.freeze
148+
klass = URI::HTTP
149+
end
146150

151+
if host = @uri.host
152+
elsif host = self['host']
153+
host.sub!(/:.*/s, ''.freeze)
154+
else
155+
host = addr
156+
end
147157
# convert the class of the URI
148-
unless scheme == @uri.scheme then
149-
new_uri = @uri.to_s.sub(/^https?/, scheme)
150-
@uri = URI new_uri
158+
if @uri.is_a?(klass)
159+
@uri.host = host
160+
@uri.port = port
161+
else
162+
@uri = klass.new(
163+
scheme, @uri.userinfo,
164+
host, port, nil,
165+
@uri.path, nil, @uri.query, nil)
151166
end
152-
153-
@uri
154167
end
155168

156169
private

0 commit comments

Comments
 (0)