diff options
author | Andre Arko <andre@arko.net> | 2011-11-16 12:53:43 -1000 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2011-11-16 12:53:43 -1000 |
commit | f05ccf805a6d2a3ed73ef9928577e8b0ebbb3c49 (patch) | |
tree | 040ee91d28a54d035ef611acbd23ff7cfdfd96b0 /actionpack/lib/action_dispatch/middleware/remote_ip.rb | |
parent | cef1e14e09e5654895f264a2cff1c0898672b1f0 (diff) | |
download | rails-f05ccf805a6d2a3ed73ef9928577e8b0ebbb3c49.tar.gz rails-f05ccf805a6d2a3ed73ef9928577e8b0ebbb3c49.tar.bz2 rails-f05ccf805a6d2a3ed73ef9928577e8b0ebbb3c49.zip |
Revert "Revert "Merge pull request #3640 from indirect/remote_ip""
This reverts commit 8d1a2b3ecde5a8745b3eaab4763a71d80ca3441f, because I have fixed the issues this commit caused in the next commit.
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..77aa4e743e 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', :all).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 |