Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3412

Show
Ignore:
Timestamp:
01/13/06 08:31:16 (3 years ago)
Author:
nzkoz
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3407 r3412  
    11*SVN* 
     2 
     3* Add support for multiple proxy servers to CgiRequest#host [gaetanot@comcast.net] 
    24 
    35* Documentation typo fix. #2367 [Blair Zajac] 
  • trunk/actionpack/lib/action_controller/cgi_process.rb

    r3150 r3412  
    8080 
    8181    def host 
    82       env["HTTP_X_FORWARDED_HOST"] || ($1 if env['HTTP_HOST'] && /^(.*):\d+$/ =~ env['HTTP_HOST']) || @cgi.host.to_s.split(":").first || '' 
     82      if env["HTTP_X_FORWARDED_HOST"]  
     83        env["HTTP_X_FORWARDED_HOST"].split(/,\s?/).last 
     84      elsif env['HTTP_HOST'] =~ /^(.*):\d+$/ 
     85        $1 
     86      else  
     87        @cgi.host.to_s.split(":").first || '' 
     88      end  
    8389    end 
    8490     
  • trunk/actionpack/test/controller/cgi_test.rb

    r3039 r3412  
    328328    @request_hash['HTTP_HOST'] = "rubyonrails.org:8080" 
    329329    assert_equal "rubyonrails.org:8080", @request.host_with_port 
     330     
     331    @request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org" 
     332    assert_equal "www.secondhost.org", @request.host 
     333     
    330334  end 
    331335