code: def before_request(self, fn):
          
          self._defer(lambda app: app.before_request(fn))
          return fn
docs: Registers a function to run before each request.
  
          For example, this can be used to open a database connection, or to load
          the logged in user from the session.
  
          The function will be called without any arguments. If it returns a
          non-None value, the value is handled as if it was the return value from
          the view, and further request handling is stopped.