1

我正在尝试修改我的简单 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

知道我需要做什么才能完成这项工作吗?谢谢你的帮助!

4

1 回答 1

1

不久前,Twisted 邮件列表上出现了一个类似的问题:

http://www.mail-archive.com/twisted-python@twistedmatrix.com/msg01080.html

正如我在那里提到的,您可能需要对一些 twisted.proxy 类进行子类化,以便它们理解 Proxy-Authenticate 和 Proxy-Authorization 标头。

于 2009-09-22T21:20:05.360 回答