Skip to content

Commit

Permalink
Provide request to Middleware.process_response()
Browse files Browse the repository at this point in the history
It appears that no middleware has taken advantage of
the builtin process_response(response) convention,
because a reference to the original request is
typically necessary to build an appropriate response.

Change-Id: If032261974eb1d756abdbd5b18892091978e2a07
  • Loading branch information
dolph committed Feb 28, 2012
1 parent 9581809 commit a7c8e2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 7 additions & 7 deletions keystone/common/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _factory(app):
def __init__(self, application):
self.application = application

def process_request(self, req):
def process_request(self, request):
"""Called on each request.
If this returns None, the next application down the stack will be
Expand All @@ -270,17 +270,17 @@ def process_request(self, req):
"""
return None

def process_response(self, response):
"""Do whatever you'd like to the response."""
def process_response(self, request, response):
"""Do whatever you'd like to the response, based on the request."""
return response

@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):
response = self.process_request(req)
def __call__(self, request):
response = self.process_request(request)
if response:
return response
response = req.get_response(self.application)
return self.process_response(response)
response = request.get_response(self.application)
return self.process_response(request, response)


class Debug(Middleware):
Expand Down
7 changes: 1 addition & 6 deletions keystone/middleware/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ def process_request(self, request):

class XmlBodyMiddleware(wsgi.Middleware):
"""De/serializes XML to/from JSON."""
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, request):
self.process_request(request)
response = request.get_response(self.application)
self.process_response(request, response)
return response

def process_request(self, request):
"""Transform the request from XML to JSON."""
Expand All @@ -153,3 +147,4 @@ def process_response(self, request, response):
response.body = serializer.to_xml(json.loads(response.body))
except:
raise exception.Error(message=response.body)
return response

0 comments on commit a7c8e2a

Please sign in to comment.