[Web-SIG] Standardized configuration

ChunWei Ho fuzzybr80 at gmail.com
Wed Jul 20 05:34:07 CEST 2005


> (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.
>


More information about the Web-SIG mailing list