mirror of
https://github.com/github/rails.git
synced 2026-01-28 15:58:03 -05:00
Fixed proxy support for lighttpd (closes #3267) [stephen_purcell@yahoo.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3894 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -75,22 +75,28 @@ module ActionController #:nodoc:
|
||||
@cgi.cookies.freeze
|
||||
end
|
||||
|
||||
def host_with_port
|
||||
if forwarded = env["HTTP_X_FORWARDED_HOST"]
|
||||
forwarded.split(/,\s?/).last
|
||||
elsif http_host = env['HTTP_HOST']
|
||||
http_host
|
||||
elsif server_name = env['SERVER_NAME']
|
||||
server_name
|
||||
else
|
||||
"#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
|
||||
end
|
||||
end
|
||||
|
||||
def host
|
||||
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
|
||||
host_with_port[/^[^:]+/]
|
||||
end
|
||||
|
||||
|
||||
def port
|
||||
@env["HTTP_X_FORWARDED_HOST"] ? standard_port : (port_from_http_host || super)
|
||||
end
|
||||
|
||||
def port_from_http_host
|
||||
$1.to_i if @env['HTTP_HOST'] && /:(\d+)$/ =~ @env['HTTP_HOST']
|
||||
if host_with_port =~ /:(\d+)$/
|
||||
$1.to_i
|
||||
else
|
||||
standard_port
|
||||
end
|
||||
end
|
||||
|
||||
def session
|
||||
|
||||
@@ -330,9 +330,27 @@ class CGIRequestTest < Test::Unit::TestCase
|
||||
|
||||
@request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
|
||||
assert_equal "www.secondhost.org", @request.host
|
||||
|
||||
end
|
||||
|
||||
def test_http_host_with_default_port_overrides_server_port
|
||||
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
||||
@request_hash['HTTP_HOST'] = "rubyonrails.org"
|
||||
assert_equal "rubyonrails.org", @request.host_with_port
|
||||
end
|
||||
|
||||
def test_host_with_port_defaults_to_server_name_if_no_host_headers
|
||||
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
||||
@request_hash.delete "HTTP_HOST"
|
||||
assert_equal "glu.ttono.us:8007", @request.host_with_port
|
||||
end
|
||||
|
||||
def test_host_with_port_falls_back_to_server_addr_if_necessary
|
||||
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
||||
@request_hash.delete "HTTP_HOST"
|
||||
@request_hash.delete "SERVER_NAME"
|
||||
assert_equal "207.7.108.53:8007", @request.host_with_port
|
||||
end
|
||||
|
||||
def test_cookie_syntax_resilience
|
||||
cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]);
|
||||
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"]
|
||||
@@ -342,5 +360,4 @@ class CGIRequestTest < Test::Unit::TestCase
|
||||
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], alt_cookies["_session_id"]
|
||||
assert_equal ["yes"], alt_cookies["is_admin"]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user