Merge branch 'remotes/merge-requests/21' (early part)
This commit is contained in:
commit
0bc86f8e5c
@ -20,7 +20,7 @@ import urllib
|
||||
import routes
|
||||
from webob import Request, exc
|
||||
|
||||
from mediagoblin import routing, util
|
||||
from mediagoblin import routing, util, middleware
|
||||
from mediagoblin.mg_globals import setup_globals
|
||||
from mediagoblin.init.celery import setup_celery_from_config
|
||||
from mediagoblin.init import (get_jinja_loader, get_staticdirector,
|
||||
@ -61,7 +61,7 @@ class MediaGoblinApp(object):
|
||||
# Get the template environment
|
||||
self.template_loader = get_jinja_loader(
|
||||
app_config.get('user_template_path'))
|
||||
|
||||
|
||||
# Set up storage systems
|
||||
self.public_store, self.queue_store = setup_storage()
|
||||
|
||||
@ -94,11 +94,22 @@ class MediaGoblinApp(object):
|
||||
# matters in always eager mode :)
|
||||
setup_workbench()
|
||||
|
||||
# instantiate application middleware
|
||||
self.middleware = [util.import_component(m)(self)
|
||||
for m in middleware.ENABLED_MIDDLEWARE]
|
||||
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
request = Request(environ)
|
||||
path_info = request.path_info
|
||||
|
||||
# pass the request through our middleware classes
|
||||
for m in self.middleware:
|
||||
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)
|
||||
|
||||
## Attach utilities to the request object
|
||||
@ -110,7 +121,7 @@ class MediaGoblinApp(object):
|
||||
# Also attach a few utilities from request.app for convenience?
|
||||
request.app = self
|
||||
request.locale = util.get_locale_from_request(request)
|
||||
|
||||
|
||||
request.template_env = util.get_jinja_env(
|
||||
self.template_loader, request.locale)
|
||||
request.db = self.db
|
||||
@ -139,7 +150,14 @@ class MediaGoblinApp(object):
|
||||
controller = util.import_component(route_match['controller'])
|
||||
request.start_response = start_response
|
||||
|
||||
return controller(request)(environ, start_response)
|
||||
# get the response from the controller
|
||||
response = controller(request)
|
||||
|
||||
# pass the response through the middleware
|
||||
for m in self.middleware[::-1]:
|
||||
m.process_response(request, response)
|
||||
|
||||
return response(environ, start_response)
|
||||
|
||||
|
||||
def paste_app_factory(global_config, **app_config):
|
||||
|
19
mediagoblin/middleware/__init__.py
Normal file
19
mediagoblin/middleware/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||
# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ENABLED_MIDDLEWARE = (
|
||||
'mediagoblin.middleware.noop:NoOpMiddleware',
|
||||
)
|
26
mediagoblin/middleware/noop.py
Normal file
26
mediagoblin/middleware/noop.py
Normal file
@ -0,0 +1,26 @@
|
||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||
# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class NoOpMiddleware(object):
|
||||
|
||||
def __init__(self, mg_app):
|
||||
self.app = mg_app
|
||||
|
||||
def process_request(self, request):
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user