How do I switch this Proxy to use Proxy-Authentication?

心不动则不痛 提交于 2019-12-11 09:47:43

问题


I'm trying to modify my simple Twisted web proxy to use "Proxy-Authentication" (username/password) instead of the current IP based authentication. Problem is, I'm new to Twisted and don't even know where to start.

Here is my Factory Class.

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

Any idea what I need to do to make this work? Thanks for your help!


回答1:


A similar question came up on the Twisted mailing list a while ago:

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

As I mentioned there, you probably need to subclass some of the twisted.proxy classes so that they understand the Proxy-Authenticate and Proxy-Authorization headers.



来源:https://stackoverflow.com/questions/1336882/how-do-i-switch-this-proxy-to-use-proxy-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!