如何将此代理切换到使用代理认证?
我正在尝试修改我的简单 Twisted 网络代理,让它使用“代理认证”(用户名/密码),而不是现在的基于 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
你知道我需要做些什么才能让它工作吗?谢谢你的帮助!
1 个回答
1
之前在Twisted的邮件列表上也有人问过类似的问题:
http://www.mail-archive.com/twisted-python@twistedmatrix.com/msg01080.html
我在那儿提到过,你可能需要创建一些新的类,继承自twisted.proxy的类,这样它们才能理解Proxy-Authenticate和Proxy-Authorization这两个头信息。