summaryrefslogtreecommitdiffstats
path: root/nova/wsgi.py
diff options
context:
space:
mode:
Diffstat (limited to 'nova/wsgi.py')
-rw-r--r--nova/wsgi.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/nova/wsgi.py b/nova/wsgi.py
index e999f76a3..00b351253 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -21,7 +21,6 @@
Utility methods for working with WSGI servers
"""
-import json
import sys
from xml.dom import minidom
@@ -35,6 +34,7 @@ import webob.dec
import webob.exc
from nova import log as logging
+from nova import utils
class WritableLogger(object):
@@ -117,20 +117,38 @@ class Application(object):
class Middleware(Application):
- """
- Base WSGI middleware wrapper. These classes require an application to be
+ """Base WSGI middleware.
+
+ These classes require an application to be
initialized that will be called next. By default the middleware will
simply call its wrapped app, or you can override __call__ to customize its
behavior.
"""
- def __init__(self, application): # pylint: disable-msg=W0231
+ def __init__(self, application):
self.application = application
+ def process_request(self, req):
+ """Called on each request.
+
+ If this returns None, the next application down the stack will be
+ executed. If it returns a response then that response will be returned
+ and execution will stop here.
+
+ """
+ return None
+
+ def process_response(self, response):
+ """Do whatever you'd like to the response."""
+ return response
+
@webob.dec.wsgify
- def __call__(self, req): # pylint: disable-msg=W0221
- """Override to implement middleware behavior."""
- return self.application
+ def __call__(self, req):
+ response = self.process_request(req)
+ if response:
+ return response
+ response = req.get_response(self.application)
+ return self.process_response(response)
class Debug(Middleware):
@@ -316,7 +334,7 @@ class Serializer(object):
try:
is_xml = (datastring[0] == '<')
if not is_xml:
- return json.loads(datastring)
+ return utils.loads(datastring)
return self._from_xml(datastring)
except:
return None
@@ -349,7 +367,7 @@ class Serializer(object):
return result
def _to_json(self, data):
- return json.dumps(data)
+ return utils.dumps(data)
def _to_xml(self, data):
metadata = self.metadata.get('application/xml', {})