Python 3.x Sanic:request.ip和request.remote\u addr之间的区别?
Sanic请求的ip和远程地址属性之间有什么区别 源代码:Python 3.x Sanic:request.ip和request.remote\u addr之间的区别?,python-3.x,http,request,ip,sanic,Python 3.x,Http,Request,Ip,Sanic,Sanic请求的ip和远程地址属性之间有什么区别 源代码: 某些代理或负载平衡器可能隐藏原始客户端ip。提到的标题可以存储此值 例如,请参阅头文件。ip仅显示直接连接Sanic的地址,而请求。remote\u addr仅显示代理提供的远程地址(例如,如果您是)。您需要根据应用程序是否在代理后运行来选择一个。要支持两者,请使用 user\u ip=request.remote\u addr或request.ip @property def ip(self): """ :retur
某些代理或负载平衡器可能隐藏原始客户端ip。提到的标题可以存储此值
例如,请参阅头文件。ip仅显示直接连接Sanic的地址,而
请求。remote\u addr
仅显示代理提供的远程地址(例如,如果您是)。您需要根据应用程序是否在代理后运行来选择一个。要支持两者,请使用
user\u ip=request.remote\u addr或request.ip
@property
def ip(self):
"""
:return: peer ip of the socket
"""
if not hasattr(self, "_socket"):
self._get_address()
return self._ip
@property
def remote_addr(self):
"""Attempt to return the original client ip based on `forwarded`,
`x-forwarded-for` or `x-real-ip`. If HTTP headers are unavailable or
untrusted, returns an empty string.
:return: original client ip.
"""
if not hasattr(self, "_remote_addr"):
self._remote_addr = self.forwarded.get("for", "")
return self._remote_addr