Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Created May 23, 2013 18:00
Show Gist options
  • Save paul-schwendenman/5638070 to your computer and use it in GitHub Desktop.
Save paul-schwendenman/5638070 to your computer and use it in GitHub Desktop.
A very simple twisted server to provide a reverse proxy
"""
This example demonstrates a reverse proxy.
Run this example with:
$ python reverse-proxy.py
Then visit http://192.168.4.13:8000/ (or http://LISTEN_IP:LISTEN_PORT) in
your web browser.
"""
from twisted.internet import reactor
from twisted.web import proxy, server
OTHER_SERVER_IP = 'localhost'
OTHER_SERVER_PORT = 8000
LISTEN_IP = '192.168.4.13'
LISTEN_PORT = 8080
class LoggingReverse(proxy.ReverseProxyResource):
def render(self, request):
print "Request from %s for %s" % (request.getClientIP(), request.uri)
super(LoggingReverse, self).render(self, request)
site = server.Site(LoggingReverse(OTHER_SERVER_IP, OTHER_SERVER_PORT, ''))
reactor.listenTCP(LISTEN_IP, site, interface=LISTEN_IP)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment