# rudimentary web server and special minimal proxy, derived from # http://www.effbot.org/librarybook/simplehttpserver.htm # simplehttpserver-example-2.py # placed under the public domain, published in # "(the eff-bot guide to) The Standard Python Library" by Fredrik Lundh 1999 import SocketServer import SimpleHTTPServer import urllib PORT = 6779 PREFIX = "/cgi-bin/proxy.cgi?url=" class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() #print "path = ", self.path if self.path[0:len(PREFIX)] == PREFIX: self.copyfile(urllib.urlopen(self.path[len(PREFIX):]), self.wfile) else: self.copyfile(open("." + self.path), self.wfile) httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy) print "serving at port", PORT httpd.serve_forever()