From: Ben Darnell Date: Thu, 3 Dec 2009 19:57:52 +0000 (-0800) Subject: Add a FallbackHandler class to allow use of other applications (e.g. X-Git-Tag: v1.0.0~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fc06caffe9a362a526e6c5480a2ebdd174eb29f;p=thirdparty%2Ftornado.git Add a FallbackHandler class to allow use of other applications (e.g. tornado.wsgi.WSGIContainer) from within a tornado.web.Application to facilitate migration from other web frameworks. --- diff --git a/tornado/web.py b/tornado/web.py index d77f0c566..7b8dd7d09 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1084,6 +1084,29 @@ class StaticFileHandler(RequestHandler): file.close() +class FallbackHandler(RequestHandler): + """A RequestHandler that wraps another HTTP server callback. + + The fallback is a callable object that accepts an HTTPRequest, + such as an Application or tornado.wsgi.WSGIContainer. This is most + useful to use both tornado RequestHandlers and WSGI in the same server. + Typical usage: + wsgi_app = tornado.wsgi.WSGIContainer( + django.core.handlers.wsgi.WSGIHandler()) + application = tornado.web.Application([ + (r"/foo", FooHandler), + (r".*", FallbackHandler, dict(fallback=wsgi_app), + ]) + """ + def __init__(self, app, request, fallback): + RequestHandler.__init__(self, app, request) + self.fallback = fallback + + def prepare(self): + self.fallback(self.request) + self._finished = True + + class OutputTransform(object): """A transform modifies the result of an HTTP request (e.g., GZip encoding)