提交 302533b1 编写于 作者: M Michael Koziarski

Add support for multiple proxy servers in HTTP_X_FORWARDED_HOST. Closes #3397


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3412 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 d40af24e
*SVN*
* Add support for multiple proxy servers to CgiRequest#host [gaetanot@comcast.net]
* Documentation typo fix. #2367 [Blair Zajac]
* Remove Upload Progress. #2871 [Sean Treadway]
......
......@@ -79,7 +79,13 @@ def cookies
end
def host
env["HTTP_X_FORWARDED_HOST"] || ($1 if env['HTTP_HOST'] && /^(.*):\d+$/ =~ env['HTTP_HOST']) || @cgi.host.to_s.split(":").first || ''
if env["HTTP_X_FORWARDED_HOST"]
env["HTTP_X_FORWARDED_HOST"].split(/,\s?/).last
elsif env['HTTP_HOST'] =~ /^(.*):\d+$/
$1
else
@cgi.host.to_s.split(":").first || ''
end
end
def port
......
......@@ -327,6 +327,10 @@ def test_http_host
@request_hash.delete "HTTP_X_FORWARDED_HOST"
@request_hash['HTTP_HOST'] = "rubyonrails.org:8080"
assert_equal "rubyonrails.org:8080", @request.host_with_port
@request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
assert_equal "www.secondhost.org", @request.host
end
def test_cookie_syntax_resilience
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册