Skip to content

Commit

Permalink
* lib/net/http/generic_request.rb (Net::HTTP::GenericRequest#exec):
Browse files Browse the repository at this point in the history
  handle req['host'] in update_uri.

* lib/net/http/generic_request.rb
  (Net::HTTP::GenericRequest#update_uri):
  use req['host'] if it is explicitly set. Even if URI is given,
  it is already used for the initial value of req['host'].
  Therefore overwritten value should be respected. [Bug #10054]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Aug 5, 2014
1 parent c165203 commit 70a2eb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
@@ -1,3 +1,14 @@
Wed Aug 6 03:18:04 2014 NARUSE, Yui <naruse@ruby-lang.org>

* lib/net/http/generic_request.rb (Net::HTTP::GenericRequest#exec):
handle req['host'] in update_uri.

* lib/net/http/generic_request.rb
(Net::HTTP::GenericRequest#update_uri):
use req['host'] if it is explicitly set. Even if URI is given,
it is already used for the initial value of req['host'].
Therefore overwritten value should be respected. [Bug #10054]

Wed Aug 6 03:17:34 2014 NARUSE, Yui <naruse@ruby-lang.org>

* lib/net/http/generic_request.rb
Expand Down
13 changes: 2 additions & 11 deletions lib/net/http/generic_request.rb
Expand Up @@ -116,15 +116,6 @@ def set_body_internal(str) #:nodoc: internal use only
#

def exec(sock, ver, path) #:nodoc: internal use only
if @uri
if @uri.port == @uri.default_port
# [Bug #7650] Amazon ECS API and GFE/1.3 disallow extra default port number
self['host'] = @uri.host
else
self['host'] = "#{@uri.host}:#{@uri.port}"
end
end

if @body
send_request_with_body sock, ver, path, @body
elsif @body_stream
Expand All @@ -148,9 +139,9 @@ def update_uri(addr, port, ssl) # :nodoc: internal use only
klass = URI::HTTP
end

if host = @uri.host
elsif host = self['host']
if host = self['host']
host.sub!(/:.*/s, ''.freeze)
elsif host = @uri.host
else
host = addr
end
Expand Down
4 changes: 2 additions & 2 deletions test/net/http/test_http.rb
Expand Up @@ -563,10 +563,10 @@ def _test_request__uri(http)
end

def _test_request__uri_host(http)
uri = URI 'http://example/'
uri = URI 'http://other.example/'

req = Net::HTTP::Get.new(uri)
req['host'] = 'other.example'
req['host'] = 'example'

res = http.request(req)

Expand Down

0 comments on commit 70a2eb6

Please sign in to comment.