How to handle a request with webapp.RequestHandler chain

GAE webapp allows one handler to be mapped to a route:

application = webapp.WSGIApplication([
                                     ('/login', gae_handlers.UserLogin),
                                     ], debug=True)

      

Is there a way to have a chain of request handlers?

I want to have a handler that authenticates before firing all other handlers.

+2


a source to share


2 answers


You can do this with either decorators or WSGI middleware.



Here's a good example of using a decorator in this answer . Nick Johnson's AEoid project uses a middleware approach.

+5


a source


I found another way



class ExtendedRequest(google.appengine.ext.webapp.WSGIApplication.REQUEST_CLASS):
    # I can basically do anything here
    def get_session_id(self):
        return self.cookies.get('session_id')

google.appengine.ext.webapp.WSGIApplication.REQUEST_CLASS = ExtendedRequest

      

0


a source







All Articles