As the title goes, you can get the client’s ip with both methods. I wonder if there is any differences. Thank you.
in the source code there goes
“/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action
_dispatch/http/request.rb” 257L, 8741C
def ip
@ip ||= super
end
# Originating IP address, usually set by the RemoteIp middleware.
def remote_ip
@remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
end
but I really don’t know the implications.
From source:
where Rack::Request looks like this
So
remote_ipgives precedence toaction_dispatch.remote_ip. That is being set byActionDispatch::RemoteIpmiddleware. You can see in that middleware’s source that it’s checking for spoofing attacks when being called, since it’s callingGetIp.newto set that env variable. That’s needed sinceremote_ipreads the ip address even through the local proxies, as Clowerweb explains.