Issue 680: Dispatch meddleware request processing post-routing

This commit is contained in:
Nathan Yergler 2011-11-26 14:34:36 -08:00
parent e4113ad5b4
commit 91cf67385a
4 changed files with 11 additions and 9 deletions

View File

@ -107,12 +107,6 @@ class MediaGoblinApp(object):
def __call__(self, environ, start_response):
request = Request(environ)
# pass the request through our meddleware classes
for m in self.meddleware:
response = m.process_request(request)
if response is not None:
return response(environ, start_response)
## Routing / controller loading stuff
path_info = request.path_info
route_match = self.routing.match(path_info)
@ -164,6 +158,13 @@ class MediaGoblinApp(object):
return render_404(request)(environ, start_response)
controller = common.import_component(route_match['controller'])
# pass the request through our meddleware classes
for m in self.meddleware:
response = m.process_request(request, controller)
if response is not None:
return response(environ, start_response)
request.start_response = start_response
# get the response from the controller

View File

@ -25,7 +25,7 @@ class BaseMeddleware(object):
def __init__(self, mg_app):
self.app = mg_app
def process_request(self, request):
def process_request(self, request, controller):
pass
def process_response(self, request, response):

View File

@ -58,7 +58,7 @@ class CsrfMeddleware(BaseMeddleware):
CSRF_KEYLEN = 64
SAFE_HTTP_METHODS = ("GET", "HEAD", "OPTIONS", "TRACE")
def process_request(self, request):
def process_request(self, request, controller):
"""For non-safe requests, confirm that the tokens are present
and match.
"""

View File

@ -19,7 +19,8 @@ from mediagoblin.meddleware import BaseMeddleware
class NoOpMeddleware(BaseMeddleware):
def process_request(self, request):
def process_request(self, request, controller):
pass
def process_response(self, request, response):