diff --git a/app/http/controllers/TestController.py b/app/http/controllers/TestController.py index 7b306e359..229e6f609 100644 --- a/app/http/controllers/TestController.py +++ b/app/http/controllers/TestController.py @@ -16,6 +16,10 @@ def change_header(self, request: Request): request.header('Content-Type', 'application/xml') return 'test' + def change_status(self, request: Request): + request.status(203) + return 'test' + def testing(self): return 'test' diff --git a/masonite/response.py b/masonite/response.py index 0d8b59cf8..878ba56fc 100644 --- a/masonite/response.py +++ b/masonite/response.py @@ -82,7 +82,8 @@ def view(self, view, status=200): Returns: string|dict|list -- Returns the data to be returned. """ - self.request.status(status) + if self.request.get_status() in (404,): + self.request.status(status) if isinstance(view, dict) or isinstance(view, list): return self.json(view) diff --git a/tests/test_response.py b/tests/test_response.py index 486ba0a51..84b9bb038 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -11,6 +11,7 @@ def setup_method(self): self.app = App() self.request = Request(generate_wsgi()).load_app(self.app) self.app.bind('Request', self.request) + self.app.bind('StatusCode', '404 Not Found') self.response = Response(self.app) def test_can_set_json(self): @@ -48,3 +49,8 @@ def test_view_can_return_integer_as_string(self): assert self.app.make('Response') == '1' assert self.request.is_status(200) + + def test_view_can_set_own_status_code(self): + + self.response.view(self.app.resolve(ControllerTest().change_status)) + assert self.request.is_status(203)