Skip to content

Instantly share code, notes, and snippets.

@Sangarshanan
Created January 2, 2021 14:49
Show Gist options
  • Save Sangarshanan/55d11a0b016e652338f28ac7feaf0847 to your computer and use it in GitHub Desktop.
Save Sangarshanan/55d11a0b016e652338f28ac7feaf0847 to your computer and use it in GitHub Desktop.
"""Basic Proxies in Python."""
"""Twisted."""
from twisted.internet import reactor
from twisted.web import proxy, server
site = server.Site(proxy.ReverseProxyResource("example.com", 80, b""))
reactor.listenTCP(8080, site)
reactor.run()
"""Tornado."""
import tornado.gen
import tornado.ioloop
import tornado.web
import tornado.httpclient
url = "http://example.com/"
class MainHandler(tornado.web.RequestHandler):
async def get(self):
req = tornado.httpclient.HTTPRequest(url)
client = tornado.httpclient.AsyncHTTPClient()
response = await client.fetch(req, raise_error=False)
self.write(response.body)
def make_app():
return tornado.web.Application([(r"/example.*", MainHandler),])
if __name__ == "__main__":
app = make_app()
app.listen(9000)
tornado.ioloop.IOLoop.current().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment