GAE middlewares for modules?
The way I approached such scenario (in a python-only project, donno about php) was to use a custom handler (inheriting webapp2.RequestHandler which I was already using for session support). In its customized dispatch() method the user info is collected and stored in the handler object itself.
The implementation of the handler exists in only one version controlled file, but which is symlinked (for GAE accessibility) in each module that references the handler. This way I don't have to manage multiple independent copies of the user and session verification code.
Assume that I have few modules on my GAE project (say A, B, C). They shares the users database and sessions.
For example: module A will manage the login/logout actions (through cookies), module B,C will handle other actions. FYI, those modules are developed in both PHP and Python.
Now, I do not want to make user & session verification codes on all 3 modules.
Is there anyway for me to put a middleware that run before all 3 modules for each request. Such as X: it will add header for each request to set the user id and some user's information if the user has logged in.
I.E: after I can implement my above idea. Each request will run through 1 in below 3 cases:

X, A
X, B
X, C

What do you say?
Thanks
Update 1: more information
The middleware, I mean the request middle ware.
If X is a middleware then it will be run before the request is passed to the app (or module), it will change the request only such as:

Do some authentication actions  
Add some headers:


X-User-Id: for authorized user id
X-User-Scopes: for scopes of authorized user

etc ...

And of course, it is independent to the inside module's language (PHP or Python or Java or ...)
The X middleware should be configured at app.yaml.