My App Engine application has a custom user model. This model is accessed frequently in the application code. I would like to simplify the code by injecting a model instance into each authenticated request before the request is handled (similar to the process_request
method of Django middleware classes).
I am using the App Engine Python2.7 standard runtime with webapp2 as the framework.
I tried creating a WSGI middleware callable that modified the WSGI environ dictionary and defined a webapp_add_wsgi_middleware
function appengine_config.py
to add the middleware, but the middleware did not run until after the request had been processed by the app.
How can I modify the request before it's handled by the application?