From 87418bb069a3357a260d518f67d46ba37994cdbb Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 23 Apr 2014 06:59:15 -0700 Subject: If an exposed method returns nothing, reply with an HTTP 204. Fixes-bug: 1311629 Change-Id: I06259adc76631d88777d1747c09dae3a67692a39 --- pecan/core.py | 4 +++- pecan/tests/test_base.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pecan/core.py b/pecan/core.py index b9c88a1..8964b4f 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -539,10 +539,12 @@ class Pecan(object): testing_variables['controller_output'] = result # set the body content - if isinstance(result, six.text_type): + if result and isinstance(result, six.text_type): resp.text = result elif result: resp.body = result + elif response.status_int == 200: + response.status = 204 # set the content type if pecan_state['content_type']: diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 5319013..279f63b 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -46,7 +46,7 @@ class TestEmptyContent(PecanTestCase): def test_empty_index(self): r = self.app_.get('/') - self.assertEqual(r.status_int, 200) + self.assertEqual(r.status_int, 204) self.assertEqual(r.headers['Content-Length'], '0') self.assertEqual(len(r.body), 0) @@ -1005,7 +1005,7 @@ class TestFileTypeExtensions(PecanTestCase): def test_hidden_file(self): r = self.app_.get('/.vimrc') - assert r.status_int == 200 + assert r.status_int == 204 assert r.body == b_('') def test_multi_dot_extension(self): -- cgit v1.2.1