1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

GetIp#to_s should never return nil. That's icky.

This commit is contained in:
Andre Arko 2011-11-14 16:43:21 -10:00
parent c7ab43ff06
commit d743954792
2 changed files with 8 additions and 6 deletions

View file

@ -155,10 +155,9 @@ module ActionDispatch
@ip ||= super
end
# Originating IP address, usually set by the RemoteIp middleware.
# Originating IP address from 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"]
end
# Returns the unique request id, which is based off either the X-Request-Id header that can

View file

@ -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