Permalink
Browse files

Merge pull request #19433 from agfor/fix_host_with_x_forwarded_host_h…

…eader

Fix handling of empty X_FORWARDED_HOST header.
  • Loading branch information...
rafaelfranca committed Mar 20, 2015
1 parent 1a91917 commit 3a4d7d8959888121f87784bbd92ae1566fdfa380
Showing with 12 additions and 1 deletion.
  1. +8 −0 actionpack/CHANGELOG.md
  2. +1 −1 actionpack/lib/action_dispatch/http/url.rb
  3. +3 −0 actionpack/test/dispatch/rack_test.rb
View
@@ -1,3 +1,11 @@
* Fix handling of empty X_FORWARDED_HOST header in raw_host_with_port
Previously, an empty X_FORWARDED_HOST header would cause
Actiondispatch::Http:URL.raw_host_with_port to return nil, causing
Actiondispatch::Http:URL.host to raise a NoMethodError.
*Adam Forsyth*
* Fix regression in functional tests. Responses should have default headers
assigned.
@@ -165,7 +165,7 @@ def protocol
# Returns the \host for this request, such as "example.com".
def raw_host_with_port
if forwarded = env["HTTP_X_FORWARDED_HOST"]
if forwarded = env["HTTP_X_FORWARDED_HOST"].presence
forwarded.split(/,\s?/).last
else
env['HTTP_HOST'] || "#{env['SERVER_NAME'] || env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
@@ -73,6 +73,9 @@ class RackRequestTest < BaseRackTest
@env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
assert_equal "www.secondhost.org", @request.host
@env['HTTP_X_FORWARDED_HOST'] = ""
assert_equal "rubyonrails.org", @request.host
end
test "http host with default port overrides server port" do

0 comments on commit 3a4d7d8

Please sign in to comment.