I'm writing a simple content filtering and access restriction proxy
using the twisted web proxy package. Here's some sample code:
#!/usr/bin/env python
from twisted.web import proxy, http
import sys
from twisted.python import log
PROXY_PORT = 80
class FilterProxyClient(proxy.ProxyClient):
def handleHeader(self, key, value):
#SOME FILTERING CODE
proxy.ProxyClient.handleHeader(self, key, value)
def handleResponsePart(self, data):
#SOME CONTENT RECOGNITION CODE
proxy.ProxyClient.handleResponsePart(self, data)
def handleResponseEnd(self):
proxy.ProxyClient.handleResponseEnd(self)
class FilterProxyFactory(proxy.ProxyClientFactory):
def buildProtocol(self, addr):
client = proxy.ProxyClientFactory.buildProtocol(self, addr)
# upgrade proxy.proxyClient object to AdpusherProxyClient
client.__class__ = FilterProxyClient
return client
class FilterProxyRequest(proxy.ProxyRequest):
protocols = {'http': AdpusherProxyFactory}
def __init__(self,*args):
proxy.ProxyRequest.__init__(self, *args)
def process(self):
#SOME FILTERING CODE
proxy.ProxyRequest.process(self)
class FilterProxy(proxy.Proxy):
def __init__(self):
proxy.Proxy.__init__(self)
def requestFactory(self, *args):
return FilterProxyRequest( *args)
class FilterProxyFactory(http.HTTPFactory):
def __init__(self):
http.HTTPFactory.__init__(self)
def buildProtocol(self, addr):
protocol = FilterProxy()
return protocol
if __name__ == "__main__":
from twisted.internet import reactor
prox = FilterProxyFactory()
reactor.listenTCP(PROXY_PORT, prox)
reactor.run( )
I'd like to know if there is a way I can set it up so that it also
handles https traffic but doesn't do anythin with the content, just so
that https traffic passes trough it.
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web