“a very simple proxy example that can be connected to and will then itself try to connect to the address passed to it.” That is practically the definition of an HTTP proxy.
There’s a really simple proxy example here: http://effbot.org/librarybook/simplehttpserver.htm
The core of it is just 3 lines:
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.copyfile(urllib.urlopen(self.path), self.wfile)
So it’s a SimpleHTTPRequestHandler
that, in response to a GET request, opens the URL in the path (a request to a proxy typically looks like “GET http://example.com/”, not like “GET /index.html”). It then just copies whatever it can read from that URL to the response.
Notet that this is really minimal. It doesn’t deal with headers at all, I believe.
BTW: path
is documented at http://docs.python.org/library/basehttpserver.html. It was set before your do*
method was called.