Fixed AbstractRequest#remote_ip for users going through proxies - Patch #228 [Eric Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@12 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2004-11-25 16:39:18 +00:00
parent 43704662ef
commit 18d614040a
2 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,7 @@
*CVS*
* Fixed AbstractRequest#remote_ip for users going through proxies - Patch #228 [Eric Hodel]
* Added Request#ssl? which is shorthand for @request.protocol == "https://"
* Added the choice to call form_tag with no arguments (resulting in a form posting to current action) [bitsweat]

View File

@ -33,17 +33,17 @@ module ActionController
# delimited list in the case of multiple chained proxies; the first is
# the originating IP.
def remote_ip
if env['HTTP_CLIENT_IP']
env['HTTP_CLIENT_IP']
elsif env['HTTP_X_FORWARDED_FOR']
remote_ip = env['HTTP_X_FORWARDED_FOR'].split(',').reject { |ip|
ip =~ /^unknown$|^(10|172\.16|192\.168)\./i
}.first
return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'
remote_ip ? remote_ip.strip : env['REMOTE_ADDR']
else
env['REMOTE_ADDR']
if env.include? 'HTTP_X_FORWARDED_FOR' then
remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
ip =~ /^unknown$|^(10|172\.16|192\.168)\./i
end
return remote_ips.first.strip unless remote_ips.empty?
end
return env['REMOTE_ADDR']
end
def request_uri