我正在尝试修改我的简单 Twisted Web 代理以使用“代理身份验证”(用户名/密码)而不是当前基于 IP 的身份验证。问题是,我是 Twisted 的新手,甚至不知道从哪里开始。
这是我的工厂班。
class ProxyFactory(http.HTTPFactory):
def __init__(self, ip, internal_ips):
http.HTTPFactory.__init__(self)
self.ip = ip
self.protocol = proxy.Proxy
self.INTERNAL_IPS = internal_ips
def buildProtocol(self, addr):
print addr
# IP based authentication -- need to switch this to use standard Proxy password authentication
if addr.host not in self.INTERNAL_IPS:
return None
#p = protocol.ServerFactory.buildProtocol(self, addr)
p = self.protocol()
p.factory = self
# timeOut needs to be on the Protocol instance cause
# TimeoutMixin expects it there
p.timeOut = self.timeOut
return p
知道我需要做什么才能完成这项工作吗?谢谢你的帮助!