diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-16 16:44:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-16 16:44:09 -0800 |
commit | 70f9b74a4988891b6cd824065bb06b7e6e19d43f (patch) | |
tree | 355dbdeb63fc182f91e7a9152219d9c74b20990d /actionpack/lib/action_dispatch/middleware/remote_ip.rb | |
parent | 4c1a1933cbc5ab96efe340a3b31ac5fee12c99c8 (diff) | |
parent | a9044d011790063e17159209f7bb1cbea255d4dd (diff) | |
download | rails-70f9b74a4988891b6cd824065bb06b7e6e19d43f.tar.gz rails-70f9b74a4988891b6cd824065bb06b7e6e19d43f.tar.bz2 rails-70f9b74a4988891b6cd824065bb06b7e6e19d43f.zip |
Merge pull request #3649 from indirect/remote_ip
Fixes for Request#remote_ip (no middleware, all proxies)
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/remote_ip.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/remote_ip.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb index ee0d19a50d..3a88f2ca43 100644 --- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb +++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb @@ -55,7 +55,10 @@ module ActionDispatch "HTTP_X_FORWARDED_FOR=#{@env['HTTP_X_FORWARDED_FOR'].inspect}" end - client_ip || forwarded_ips.last || remote_addrs.first + not_proxy = client_ip || forwarded_ips.last || remote_addrs.first + + # Return first REMOTE_ADDR if there are no other options + not_proxy || ips_from('REMOTE_ADDR', :allow_proxies).first end def to_s @@ -66,9 +69,9 @@ module ActionDispatch protected - def ips_from(header) + def ips_from(header, allow_proxies = false) ips = @env[header] ? @env[header].strip.split(/[,\s]+/) : [] - ips.reject{|ip| ip =~ @middleware.proxies } + allow_proxies ? ips : ips.reject{|ip| ip =~ @middleware.proxies } end end |