> (b) > Have chain application = authmiddleware(fileserverapp) > Use Handlers, as Ian suggested, and in the fileserverapp's init: > Handlers( > IfTest(method=GET,MimeOkForGzip=True, RunApp=gzipmiddleware(doGET)), > IfTest(method=GET,MimeOkForGzip=False, RunApp=doGET), > IfTest(method=POST,MimeOkForGzip=True, RunApp=gzipmiddleware(doPOST)), > IfTest(method=POST,MimeOkForGzip=False, RunApp=doPOST), > IfTest(method=PUT, RunApp=doPOST) > )
It was Graham who suggested the use of Handlers initially. Sincere apologies for my confusion. > (c) > Make gzipmiddleware a service in the following form: > class gzipmiddleware: > def __init__(self, application=None, configparam=None): > self._application = application > .... > def __call__(self, environ, start_response, application=None, > configparam=None): > if application and configparam is specified, use them instead of > the init values > do start_response > call self._application(environ, start_response) as iterable > get each iterator output and zip and yield it. > > This "middleware" is still compatible with PEP-333, but can also be used as: > #on main application initialization, create a gzipservice and put it > in environ without > #specifying application or configparams for init(): > environ['service.gzip'] = gzipmiddleware() > > Modify fileserverapp to: > def fileserverapp(environ, start_response): > if(GET): > if(mimetype ok for gzip): > gzipservice = environ['service.gzip'] > return gzipservice(environ, start_response, doGET, > gzipconfigparams) > else: return doGET(environ, start_response) > if(POST): > if(mimetype ok for gzip): > gzipservice = environ['service.gzip'] > return gzipservice(environ, start_response, doPOST, > gzipconfigparams) > else: return doPOST(environ, start_response) > if(PUT): doPUT(environ, start_response) > > The main difference here is that you don't have to initialize full > application chains for each possible middleware-path for the request. > This would be very useful if you had many middleware in the chain with > many permutations as to which middleware are needed > > You could also instead put a service factory object into environ, it > will return the gzipmiddleware object as a service if already exist, > otherwise it will create it and then return it. > _______________________________________________ Web-SIG mailing list Web-SIG@python.org Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com