diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-03-20 18:28:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-03-20 18:28:21 -0300 |
commit | 37e002ba96ad7f08796cdc7515de345ac5a88544 (patch) | |
tree | 14e7167c3ab972c50ae6c67b760d9f3d78336674 | |
parent | 7c7d9dcf5a966a5490fe99230ab9513d73df9630 (diff) | |
parent | b49cac80de2d0245d8a704eebf555c54371b41d8 (diff) | |
download | rails-37e002ba96ad7f08796cdc7515de345ac5a88544.tar.gz rails-37e002ba96ad7f08796cdc7515de345ac5a88544.tar.bz2 rails-37e002ba96ad7f08796cdc7515de345ac5a88544.zip |
Merge pull request #19433 from agfor/fix_host_with_x_forwarded_host_header
Fix handling of empty X_FORWARDED_HOST header.
-rw-r--r-- | actionpack/CHANGELOG.md | 8 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 3 |
3 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 700a446af6..3f6cb5a5b1 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -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* + * Drop request class from RouteSet constructor. If you would like to use a custom request class, please subclass and implement diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 7da6301ac4..f5b709ccd6 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -229,7 +229,7 @@ module ActionDispatch # req = Request.new 'HTTP_HOST' => 'example.com:8080' # req.raw_host_with_port # => "example.com:8080" 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']}" diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index ee8e915610..61cc4dcd7e 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -435,6 +435,9 @@ class RequestHost < BaseRequestTest request = stub_request 'HTTP_X_FORWARDED_HOST' => "www.firsthost.org, www.secondhost.org" assert_equal "www.secondhost.org", request.host + + request = stub_request 'HTTP_X_FORWARDED_HOST' => "", 'HTTP_HOST' => "rubyonrails.org" + assert_equal "rubyonrails.org", request.host end test "http host with default port overrides server port" do |