本文整理汇总了Python中twisted.web.server.Request.getClientIP方法的典型用法代码示例。如果您正苦于以下问题:Python Request.getClientIP方法的具体用法?Python Request.getClientIP怎么用?Python Request.getClientIP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.server.Request
的用法示例。
在下文中一共展示了Request.getClientIP方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getClientIP
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import getClientIP [as 别名]
def getClientIP(self):
"If there's an X-Forwarded-For, treat that as the client IP."
forwarded_for = self.getHeader('x-forwarded-for')
if forwarded_for is not None:
return forwarded_for
else:
return Request.getClientIP(self)
示例2: getClientIP
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import getClientIP [as 别名]
def getClientIP(self, **kwargs):
"""Override base getClientIP to be X-Real-IP aware.
Arguments:
honor_xrealip (bool)(optional) - (If present, overrides the default
for honor_xrealip specified in the config file.)
Whether or not to prefer the value of
the X-Real-IP header if present.
"""
if kwargs.has_key("honor_xrealip"):
honor_xrealip = kwargs["honor_xrealip"]
else:
honor_xrealip = self.site.honor_xrealip
if honor_xrealip and self.getHeader("X-Real-IP"):
return self.getHeader("X-Real-IP")
return Request.getClientIP(self)
示例3: getClientIP
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import getClientIP [as 别名]
def getClientIP(self):
"""Get the clients IP address. Evaluates allowed proxys (from localhost)"""
ip = Request.getClientIP(self)
if ip in ('::1', '127.0.0.1'):
return self.requestHeaders.getRawHeaders('X-Forwarded-For', [ip])[-1]
return ip
示例4: getClientIP
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import getClientIP [as 别名]
def getClientIP(self):
real_ip = self.getHeader("X-Real-IP")
if real_ip:
return real_ip
else:
Request.getClientIP(self)
示例5: getClientIP
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import getClientIP [as 别名]
def getClientIP(self):
if self.requestHeaders.hasHeader('x-forwarded-for'):
return self.requestHeaders.getRawHeaders(b"x-forwarded-for")[0].split(b",")[0].strip()
if self.requestHeaders.hasHeader('x-real-ip'):
return self.requestHeaders.getRawHeaders(b"x-real-ip")[0].split(b",")[0].strip()
return Request.getClientIP(self)