I want to write a program that changes the HTTP headers in my requests that are sent by my web-browser. I believe it can be done with a proxy server. So, I'd like to write a proxy server.
I study programming. How can I do this in Python?
I want to write a program that changes the HTTP headers in my requests that are sent by my web-browser. I believe it can be done with a proxy server. So, I'd like to write a proxy server.
I study programming. How can I do this in Python?
Look at the Twisted framework, particularly Twisted Web. It's all freely available under MIT, so you can build off and/or modify it.
See also Python Twisted Examples.
While Twisted, as recommended by @Matthew, is awesome, easier to learn, understand and modify might be this tiny example -- far away from the "production quality" and scalability that Twisted can offer, but, you could start with it to understand the issues better.
For a wide variety of open-source HTTP proxies written in Python, I recommend this list -- that reference has proxies for all tastes built on top of threading, Twisted, asyncore, and other technologies yet!
Good example below on how to do this without the overhead of a framework.
WSGI may be a little easier to get your head around. So I'll throw paste.proxy out there either as something to build on or as a reference.