Rename MediaGoblin middleware to meddleware to avoid confusion w/ wsgi middleware
hehehehehe, "meddleware"
This commit is contained in:
parent
4da6efb459
commit
ce5ae8da19
@ -20,7 +20,7 @@ import urllib
|
|||||||
import routes
|
import routes
|
||||||
from webob import Request, exc
|
from webob import Request, exc
|
||||||
|
|
||||||
from mediagoblin import routing, middleware
|
from mediagoblin import routing, meddleware
|
||||||
from mediagoblin.tools import common, translate, template
|
from mediagoblin.tools import common, translate, template
|
||||||
from mediagoblin.tools.response import render_404
|
from mediagoblin.tools.response import render_404
|
||||||
from mediagoblin.tools import request as mg_request
|
from mediagoblin.tools import request as mg_request
|
||||||
@ -100,15 +100,15 @@ class MediaGoblinApp(object):
|
|||||||
# matters in always eager mode :)
|
# matters in always eager mode :)
|
||||||
setup_workbench()
|
setup_workbench()
|
||||||
|
|
||||||
# instantiate application middleware
|
# instantiate application meddleware
|
||||||
self.middleware = [common.import_component(m)(self)
|
self.meddleware = [common.import_component(m)(self)
|
||||||
for m in middleware.ENABLED_MIDDLEWARE]
|
for m in meddleware.ENABLED_MEDDLEWARE]
|
||||||
|
|
||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
request = Request(environ)
|
request = Request(environ)
|
||||||
|
|
||||||
# pass the request through our middleware classes
|
# pass the request through our meddleware classes
|
||||||
for m in self.middleware:
|
for m in self.meddleware:
|
||||||
response = m.process_request(request)
|
response = m.process_request(request)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
return response(environ, start_response)
|
return response(environ, start_response)
|
||||||
@ -169,8 +169,8 @@ class MediaGoblinApp(object):
|
|||||||
# get the response from the controller
|
# get the response from the controller
|
||||||
response = controller(request)
|
response = controller(request)
|
||||||
|
|
||||||
# pass the response through the middleware
|
# pass the response through the meddleware
|
||||||
for m in self.middleware[::-1]:
|
for m in self.meddleware[::-1]:
|
||||||
m.process_response(request, response)
|
m.process_response(request, response)
|
||||||
|
|
||||||
return response(environ, start_response)
|
return response(environ, start_response)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
ENABLED_MIDDLEWARE = (
|
ENABLED_MEDDLEWARE = (
|
||||||
'mediagoblin.middleware.noop:NoOpMiddleware',
|
'mediagoblin.meddleware.noop:NoOpMeddleware',
|
||||||
'mediagoblin.middleware.csrf:CsrfMiddleware',
|
'mediagoblin.meddleware.csrf:CsrfMeddleware',
|
||||||
)
|
)
|
@ -47,8 +47,8 @@ def render_csrf_form_token(request):
|
|||||||
return form.csrf_token
|
return form.csrf_token
|
||||||
|
|
||||||
|
|
||||||
class CsrfMiddleware(object):
|
class CsrfMeddleware(object):
|
||||||
"""CSRF Protection Middleware
|
"""CSRF Protection Meddleware
|
||||||
|
|
||||||
Adds a CSRF Cookie to responses and verifies that it is present
|
Adds a CSRF Cookie to responses and verifies that it is present
|
||||||
and matches the form token for non-safe requests.
|
and matches the form token for non-safe requests.
|
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
class NoOpMiddleware(object):
|
class NoOpMeddleware(object):
|
||||||
|
|
||||||
def __init__(self, mg_app):
|
def __init__(self, mg_app):
|
||||||
self.app = mg_app
|
self.app = mg_app
|
@ -50,9 +50,9 @@ $ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests ./bin/nosetests"""
|
|||||||
class BadCeleryEnviron(Exception): pass
|
class BadCeleryEnviron(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
class TestingMiddleware(object):
|
class TestingMeddleware(object):
|
||||||
"""
|
"""
|
||||||
Middleware for the Unit tests
|
Meddleware for the Unit tests
|
||||||
|
|
||||||
It might make sense to perform some tests on all
|
It might make sense to perform some tests on all
|
||||||
requests/responses. Or prepare them in a special
|
requests/responses. Or prepare them in a special
|
||||||
@ -60,7 +60,7 @@ class TestingMiddleware(object):
|
|||||||
for being valid html *after* being rendered.
|
for being valid html *after* being rendered.
|
||||||
|
|
||||||
This module is getting inserted at the front of the
|
This module is getting inserted at the front of the
|
||||||
middleware list, which means: requests are handed here
|
meddleware list, which means: requests are handed here
|
||||||
first, responses last. So this wraps up the "normal"
|
first, responses last. So this wraps up the "normal"
|
||||||
app.
|
app.
|
||||||
|
|
||||||
@ -149,11 +149,11 @@ def get_test_app(dump_old_app=True):
|
|||||||
test_app = loadapp(
|
test_app = loadapp(
|
||||||
'config:' + TEST_SERVER_CONFIG)
|
'config:' + TEST_SERVER_CONFIG)
|
||||||
|
|
||||||
# Insert the TestingMiddleware, which can do some
|
# Insert the TestingMeddleware, which can do some
|
||||||
# sanity checks on every request/response.
|
# sanity checks on every request/response.
|
||||||
# Doing it this way is probably not the cleanest way.
|
# Doing it this way is probably not the cleanest way.
|
||||||
# We'll fix it, when we have plugins!
|
# We'll fix it, when we have plugins!
|
||||||
mg_globals.app.middleware.insert(0, TestingMiddleware(mg_globals.app))
|
mg_globals.app.meddleware.insert(0, TestingMeddleware(mg_globals.app))
|
||||||
|
|
||||||
app = TestApp(test_app)
|
app = TestApp(test_app)
|
||||||
MGOBLIN_APP = app
|
MGOBLIN_APP = app
|
||||||
|
@ -21,7 +21,7 @@ from mediagoblin import mg_globals
|
|||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
from mediagoblin.tools import common
|
from mediagoblin.tools import common
|
||||||
from mediagoblin.tools.translate import setup_gettext
|
from mediagoblin.tools.translate import setup_gettext
|
||||||
from mediagoblin.middleware.csrf import render_csrf_form_token
|
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
||||||
|
|
||||||
|
|
||||||
SETUP_JINJA_ENVS = {}
|
SETUP_JINJA_ENVS = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user