summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-04-23 06:59:15 -0700
committerRyan Petrello <lists@ryanpetrello.com>2014-04-23 07:47:24 -0700
commit87418bb069a3357a260d518f67d46ba37994cdbb (patch)
treef55ad841101e8cd888eb1623e6a1e2f972bdaf83
parentc047087b72d37f094320e3bdff3fc24a79551ea8 (diff)
downloadpecan-87418bb069a3357a260d518f67d46ba37994cdbb.tar.gz
If an exposed method returns nothing, reply with an HTTP 204.
Fixes-bug: 1311629 Change-Id: I06259adc76631d88777d1747c09dae3a67692a39
-rw-r--r--pecan/core.py4
-rw-r--r--pecan/tests/test_base.py4
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):