I have a very simple klein script that is just a reverse-proxy:
from klein import run, route, Klein
from twisted.web.proxy import ReverseProxyResource
@route('/')
def home(request, branch=True):
return ReverseProxyResource('www.example.com', 80, ''.encode('utf-8'))
run("MY_IP", 80)
The only problem is the CSS doesn't work when the website is calling it using relative paths /css/example
; I'm not sure how to fix this. I'm open to any suggestions.
I'm using Python-3.3.
This first block of code based on yours was my first pass, but it doesn't work.
It appeared to work for things like
GET /a
, but that's because/<path>
doesn't include additional/
's. So anything that is deeper than one level won't get proxied.Looking into
@route
, it useswerkzeug
underneath which doesn't appear to allow arbitrary wildcards:If you drop down into
twisted
, though, you can simply do this:If you want to catch, log, modify, etc, each request, you can subclass
ReverseProxyResource
and overriderender()
. Note: you also have to overridegetChild()
due to a bug:Output: