=== modified file 'django/core/handlers/base.py'
|
|
|
|
| 120 | 120 | view_name = callback.__class__.__name__ + '.__call__' # If it's a class |
| 121 | 121 | raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name)) |
| 122 | 122 | |
| | 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 | |
| 123 | 128 | return response |
| 124 | 129 | except http.Http404, e: |
| 125 | 130 | logger.warning('Not Found: %s' % request.path, |
=== modified file 'django/core/handlers/modpython.py'
|
|
|
|
| 189 | 189 | response = http.HttpResponseBadRequest() |
| 190 | 190 | else: |
| 191 | 191 | 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) |
| 197 | 192 | finally: |
| 198 | 193 | signals.request_finished.send(sender=self.__class__) |
| 199 | 194 | |
=== modified file 'django/core/handlers/wsgi.py'
|
|
|
|
| 254 | 254 | response = http.HttpResponseBadRequest() |
| 255 | 255 | else: |
| 256 | 256 | 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) |
| 262 | 257 | finally: |
| 263 | 258 | signals.request_finished.send(sender=self.__class__) |
| 264 | 259 | |
=== modified file 'tests/regressiontests/middleware_exceptions/tests.py'
|
|
|
|
| 6 | 6 | class TestException(Exception): |
| 7 | 7 | pass |
| 8 | 8 | |
| 9 | | class TestMiddleware(object): |
| | 9 | class TestRequestMiddleware(object): |
| 10 | 10 | def process_request(self, request): |
| 11 | 11 | raise TestException('Test Exception') |
| 12 | 12 | |
| | 13 | class TestResponseMiddleware(object): |
| | 14 | def process_response(self, request, response): |
| | 15 | raise TestException('Test Exception') |
| | 16 | |
| 13 | 17 | class MiddlewareExceptionTest(TestCase): |
| 14 | 18 | def setUp(self): |
| 15 | 19 | self.exceptions = [] |
| … |
… |
|
| 23 | 27 | def _on_request_exception(self, sender, request, **kwargs): |
| 24 | 28 | self.exceptions.append(sys.exc_info()) |
| 25 | 29 | |
| 26 | | def test_process_request(self): |
| 27 | | self.client.handler._request_middleware.insert(0, TestMiddleware().process_request) |
| | 30 | def _assert_exception_handled(self): |
| 28 | 31 | try: |
| 29 | | response = self.client.get('/') |
| | 32 | response = self.client.get('/middleware_exceptions/') |
| 30 | 33 | except TestException, e: |
| 31 | 34 | # Test client indefinitely re-raises any exceptions being raised |
| 32 | 35 | # during request handling. Hence actual testing that exception was |
| … |
… |
|
| 38 | 41 | self.assertEquals(len(self.exceptions), 1) |
| 39 | 42 | exception, value, tb = self.exceptions[0] |
| 40 | 43 | 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() |