gpt4 book ai didi

ruby-on-rails - Rails 中的 request.remote_ip 和 request.ip 有什么区别?

转载 作者:数据小太阳 更新时间:2023-10-29 06:19:57 26 4
gpt4 key购买 nike

如题所示,两种方法都可以获取到客户端的ip。我想知道是否有任何差异。谢谢。

源码里有

"/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

但我真的不知道其中的含义。

最佳答案

request.ip 返回客户端 ip,即使该客户端是代理也是如此。

request.remote_ip 更聪明,获取实际客户端 ip。这只有在沿途的所有代理设置 X-Forwarded-For 时才能完成。标题。

关于ruby-on-rails - Rails 中的 request.remote_ip 和 request.ip 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10997005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com