views:

300

answers:

1

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: 

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

http://www.mail-archive.com/[email protected]/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.

Kevin Horn