Skip to content

Instantly share code, notes, and snippets.

@grav
Last active July 4, 2016 09:17
Show Gist options
  • Save grav/ad389981e0d7c1dd79ef0567760ce54b to your computer and use it in GitHub Desktop.
Save grav/ad389981e0d7c1dd79ef0567760ce54b to your computer and use it in GitHub Desktop.
import SimpleHTTPServer
import SocketServer
import urllib
import re
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
match = re.search('^/proxy.ashx?\?url=(.+)$',self.path)
if match:
self.send_response(200)
self.end_headers()
url = match.group(1)
print url
self.copyfile(urllib.urlopen(url), self.wfile)
else:
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
PORT = 8001
httpd = SocketServer.TCPServer(("", PORT), Proxy)
print "serving at port", PORT
httpd.serve_forever()
@grav
Copy link
Author

grav commented Jul 4, 2016

Proxy certain requests, otherwise just load from disk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment