So i've looked around at a few things involving writting an HTTP Proxy using python and the Twisted framework.
Essentially, like some other questions, I'd like to be able to modify the data that will be sent back to the browser. That is, the browser requests a resource and the proxy will fetch it. Before the resource is returned to the browser, i'd like to be able to modify ANY (HTTP headers AND content) content.
This ( Need help writing a twisted proxy ) was what I initially found. I tried it out, but it didn't work for me. I also found this ( Python Twisted proxy - how to intercept packets ) which i thought would work, however I can only see the HTTP requests from the browser.
I am looking for any advice. Some thoughts I have are to use the ProxyClient and ProxyRequest classes and override the functions, but I read that the Proxy class itself is a combination of the both.
For those who may ask to see some code, it should be noted that I have worked with only the above two examples. Any help is great.
Thanks.
To create
ProxyFactory
that can modify server response headers, content you could overrideProxyClient.handle*()
methods:I've got this solution by looking at the source of
twisted.web.proxy
. I don't know how idiomatic it is.To run it as a script or via
twistd
, add at the end:Usage
In another terminal:
For two-way proxy using
twisted
see the article:http://sujitpal.blogspot.com/2010/03/http-debug-proxy-with-twisted.html