Ticket #14523: 14523-review.diff

File 14523-review.diff, 3.9 KB (added by Ivan Sagalaev, 14 years ago)

Patch for review only

  • django/core/handlers/base.py

    === modified file 'django/core/handlers/base.py'
     
    120120                        view_name = callback.__class__.__name__ + '.__call__' # If it's a class
    121121                    raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
    122122
     123                # Apply response middleware
     124                for middleware_method in self._response_middleware:
     125                    response = middleware_method(request, response)
     126                response = self.apply_response_fixes(request, response)
     127
    123128                return response
    124129            except http.Http404, e:
    125130                logger.warning('Not Found: %s' % request.path,
  • django/core/handlers/modpython.py

    === modified file 'django/core/handlers/modpython.py'
     
    189189                response = http.HttpResponseBadRequest()
    190190            else:
    191191                response = self.get_response(request)
    192 
    193                 # Apply response middleware
    194                 for middleware_method in self._response_middleware:
    195                     response = middleware_method(request, response)
    196                 response = self.apply_response_fixes(request, response)
    197192        finally:
    198193            signals.request_finished.send(sender=self.__class__)
    199194
  • django/core/handlers/wsgi.py

    === modified file 'django/core/handlers/wsgi.py'
     
    254254                response = http.HttpResponseBadRequest()
    255255            else:
    256256                response = self.get_response(request)
    257 
    258                 # Apply response middleware
    259                 for middleware_method in self._response_middleware:
    260                     response = middleware_method(request, response)
    261                 response = self.apply_response_fixes(request, response)
    262257        finally:
    263258            signals.request_finished.send(sender=self.__class__)
    264259
  • tests/regressiontests/middleware_exceptions/tests.py

    === modified file 'tests/regressiontests/middleware_exceptions/tests.py'
     
    66class TestException(Exception):
    77    pass
    88
    9 class TestMiddleware(object):
     9class TestRequestMiddleware(object):
    1010    def process_request(self, request):
    1111        raise TestException('Test Exception')
    1212
     13class TestResponseMiddleware(object):
     14    def process_response(self, request, response):
     15        raise TestException('Test Exception')
     16
    1317class MiddlewareExceptionTest(TestCase):
    1418    def setUp(self):
    1519        self.exceptions = []
     
    2327    def _on_request_exception(self, sender, request, **kwargs):
    2428        self.exceptions.append(sys.exc_info())
    2529
    26     def test_process_request(self):
    27         self.client.handler._request_middleware.insert(0, TestMiddleware().process_request)
     30    def _assert_exception_handled(self):
    2831        try:
    29             response = self.client.get('/')
     32            response = self.client.get('/middleware_exceptions/')
    3033        except TestException, e:
    3134            # Test client indefinitely re-raises any exceptions being raised
    3235            # during request handling. Hence actual testing that exception was
     
    3841        self.assertEquals(len(self.exceptions), 1)
    3942        exception, value, tb = self.exceptions[0]
    4043        self.assertEquals(value.args, ('Test Exception', ))
     44
     45    def test_process_request(self):
     46        self.client.handler._request_middleware.insert(0, TestRequestMiddleware().process_request)
     47        self._assert_exception_handled()
     48
     49    def test_process_response(self):
     50        self.client.handler._response_middleware.insert(0, TestResponseMiddleware().process_response)
     51        self._assert_exception_handled()
Back to Top