views:

851

answers:

4

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?

+6  A: 

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.

Matthew Flaschen
+1  A: 

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!

Alex Martelli
+3  A: 

Good example below on how to do this without the overhead of a framework.

http://www.warriorhut.org/whatwg/websocket-proxy.py

SpliFF
A: 

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.

http://pythonpaste.org/modules/proxy.html

Tom Willis