aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-11-16 16:44:09 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-16 16:44:09 -0800
commit70f9b74a4988891b6cd824065bb06b7e6e19d43f (patch)
tree355dbdeb63fc182f91e7a9152219d9c74b20990d /actionpack/lib/action_dispatch
parent4c1a1933cbc5ab96efe340a3b31ac5fee12c99c8 (diff)
parenta9044d011790063e17159209f7bb1cbea255d4dd (diff)
downloadrails-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')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb3
-rw-r--r--actionpack/lib/action_dispatch/middleware/remote_ip.rb9
2 files changed, 7 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index b10f6b48c7..69ca050d0c 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -157,8 +157,7 @@ module ActionDispatch
# Originating IP address, usually set by the RemoteIp middleware.
def remote_ip
- # Coerce the remote_ip object into a string, because to_s could return nil
- @remote_ip ||= @env["action_dispatch.remote_ip"].to_s || ip
+ @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
end
# Returns the unique request id, which is based off either the X-Request-Id header that can
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