I write a router that takes the path of a requests, match it against a regex and calls a WSGI handler, if the regex matches. The dict with the matching capturing groups is added to the envrion. Is it bad style to modify the environ with WSGI middleware?
But is that what WSGI middleware was invented for? I've just read WSGI Middleware Considered Harmful and wonder whether I should rewrite my router to be no longer a middleware. An application becomes dependend on my middleware, if it uses the dict with capturing groups. On the other hand no application has to use this additional dict. I could also forego the path param extraction and reduce the router to the routing, but then each application has to rerun the regex a second time for path parameter extraction.
So what to do:
- leaving as is; with routing, path param extraction and
environ
manipulation - make the router a WSGI application and the current WSGI applications framework specific handlers
- reduce the router to routing and extract perform regex matching a second time for path parameter extraction in the application to which the request was routed