[Web-SIG] Middleware stack construction
Phillip J. Eby
pje at telecommunity.com
Tue Sep 12 17:19:05 CEST 2006
At 11:12 AM 9/12/2006 +0200, David Fraser wrote:
>Hi
>
>We've been trying to manage how we handle the middleware stack in our
>web framework. The PEP doesn't specify any standard way of doing this
>and the example is constructed with the next item in the stack as a
>parameter.
>
>Our approach is to pass a WSGIStack variable in the environment
>variables and get each layer of middleware to pop off the next layer and
>call it, thus:
>
>def run_child(self, environ, startresponse):
> child = environ["j5_WSGIStack"].pop()
> return child(environ, startresponse)
>
>so that the middleware can transform that in whichever way it wants...
>
>Does this fit in well with how other people are doing things? Just curious
That's an interesting concept. I don't think anybody else has come up with
it though.
I'll certainly steal it if I ever get around to creating a competitor to
Paste Deploy. :) But I imagine I'd use a linked list of tuples instead of
popping from a list, e.g.:
child, environ["my.middleware.stack"] = environ["my.middleware.stack"]
This would allow the same chain to be used for every call, without copying,
and it's probably faster than pop() as well, at least under CPython.
More information about the Web-SIG
mailing list