Вот написал на коленке
from paste.proxy import TransparentProxy
from webob import Request
from webob.exc import HTTPForbidden
class SimpleProxy(object):
def __init__(self, proxy):
self.proxy = proxy
def do_proxy(self, req, environ, start_response):
req.remove_conditional_headers()
resp = req.get_response(self.proxy)
resp.decode_content()
return resp
def __call__(self, environ, start_response):
req = Request(environ)
resp = self.do_proxy(req, environ, start_response)
return resp(environ, start_response)
class XXXProxy(SimpleProxy):
def do_proxy(self, req, environ, start_response):
resp = super(XXXProxy, self).do_proxy(req, environ, start_response)
if not self.valid(resp.body):
return HTTPForbidden()
return resp
def valid(self, body):
return not 'xxx' in body
def main():
app = XXXProxy(TransparentProxy())
from paste.httpserver import serve
serve(app, 'localhost', 3127)
if __name__ == '__main__':
main()