Changeset 3894
- Timestamp:
- 03/16/06 04:16:08 (3 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller/cgi_process.rb (modified) (1 diff)
- trunk/actionpack/test/controller/cgi_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/cgi_process.rb
r3777 r3894 76 76 end 77 77 78 def host_with_port 79 if forwarded = env["HTTP_X_FORWARDED_HOST"] 80 forwarded.split(/,\s?/).last 81 elsif http_host = env['HTTP_HOST'] 82 http_host 83 elsif server_name = env['SERVER_NAME'] 84 server_name 85 else 86 "#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}" 87 end 88 end 89 78 90 def host 79 if @env["HTTP_X_FORWARDED_HOST"] 80 @env["HTTP_X_FORWARDED_HOST"].split(/,\s?/).last 81 elsif @env['HTTP_HOST'] =~ /^(.*):\d+$/ 82 $1 83 else 84 @cgi.host.to_s.split(":").first || '' 85 end 86 end 87 91 host_with_port[/^[^:]+/] 92 end 93 88 94 def port 89 @env["HTTP_X_FORWARDED_HOST"] ? standard_port : (port_from_http_host || super)90 end91 92 def port_from_http_host93 $1.to_i if @env['HTTP_HOST'] && /:(\d+)$/ =~ @env['HTTP_HOST']95 if host_with_port =~ /:(\d+)$/ 96 $1.to_i 97 else 98 standard_port 99 end 94 100 end 95 101 trunk/actionpack/test/controller/cgi_test.rb
r3412 r3894 331 331 @request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org" 332 332 assert_equal "www.secondhost.org", @request.host 333 334 end 335 333 end 334 335 def test_http_host_with_default_port_overrides_server_port 336 @request_hash.delete "HTTP_X_FORWARDED_HOST" 337 @request_hash['HTTP_HOST'] = "rubyonrails.org" 338 assert_equal "rubyonrails.org", @request.host_with_port 339 end 340 341 def test_host_with_port_defaults_to_server_name_if_no_host_headers 342 @request_hash.delete "HTTP_X_FORWARDED_HOST" 343 @request_hash.delete "HTTP_HOST" 344 assert_equal "glu.ttono.us:8007", @request.host_with_port 345 end 346 347 def test_host_with_port_falls_back_to_server_addr_if_necessary 348 @request_hash.delete "HTTP_X_FORWARDED_HOST" 349 @request_hash.delete "HTTP_HOST" 350 @request_hash.delete "SERVER_NAME" 351 assert_equal "207.7.108.53:8007", @request.host_with_port 352 end 353 336 354 def test_cookie_syntax_resilience 337 355 cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]); … … 343 361 assert_equal ["yes"], alt_cookies["is_admin"] 344 362 end 345 346 363 end