1

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()
user1762250
  • 105
  • 1
  • 1
  • 7
  • Surely there is a method for data going the other way? Perhaps something to do with a "response". –  Mar 21 '13 at 17:48
  • 1
    see [this answer that shows how to access responses](http://stackoverflow.com/a/9469400/4279). – jfs Mar 21 '13 at 17:58

0 Answers0