I am trying to write a proxy in Twisted that logs all traffic going through it in both directions. So far I can capture requests (GET, POST, etc.) but not the responses (can't see html of webpages).
from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
from twisted.protocols import basic
#log.startLogging(sys.stdout)
class MyProxy(proxy.Proxy):
def dataReceived(self, data):
# Modify the data here
print data
# perform the default functionality on modified data
return proxy.Proxy.dataReceived(self, data)
class ProxyFactory(http.HTTPFactory):
#protocol = proxy.Proxy
protocol=MyProxy
reactor.listenTCP(8080, ProxyFactory())
reactor.run()