Ruby on rails Rails ActionController:request.remote\u ip和request.remote\u addr之间的差异
在ActionController源中,本地请求定义如下:Ruby on rails Rails ActionController:request.remote\u ip和request.remote\u addr之间的差异,ruby-on-rails,client,request,ip-address,actioncontroller,Ruby On Rails,Client,Request,Ip Address,Actioncontroller,在ActionController源中,本地请求定义如下: def local_request? #:doc: request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST end 在我的应用程序中,如果请求来自特定的IP范围,我希望使用不同的逻辑。request.remote\u addr和request.remote\u ip之间有什么区别,我应该使用哪一个?似乎是这样的情况,remote\u
def local_request? #:doc:
request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
end
在我的应用程序中,如果请求来自特定的IP范围,我希望使用不同的逻辑。
request.remote\u addr
和request.remote\u ip
之间有什么区别,我应该使用哪一个?似乎是这样的情况,remote\u addr
按原样返回remote\u addr
环境变量的值,而remote_ip
将根据HTTP_X_FORWARDED_FOR
和HTTP_CLIENT_ip
变量的存在来调整此值,例如当您的客户端通过代理转发时可能会出现的情况
对
本地\u请求进行双重检查?
只是一种确定用户来自本地机器的方法,而不是简单地通过本地代理从其他地方转发。我是远程\u ip
当前实现的作者,它包括检查ip欺骗攻击,并正确处理多个X-Forwarded-For
头。不过有一个很大的警告:只有一些RubyWeb服务器支持多个头,所以值可能仍然是错误的
我写了测试最流行的Ruby应用服务器的结果,您可能想检查重复的头是否对您的应用程序有影响