diff options
author | Julien Danjou <julien@danjou.info> | 2013-09-26 14:35:34 +0200 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2013-09-26 17:32:06 +0200 |
commit | 5d55e2a2d0e67d79d0ffeaab0866b10284deb1d7 (patch) | |
tree | 71c0cb849627a0727f187c08b4664a2f8af12043 | |
parent | 435e5fa34a6a87129f6922c18fa36e26d60e4e7f (diff) | |
download | pecan-5d55e2a2d0e67d79d0ffeaab0866b10284deb1d7.tar.gz |
core: do not try to set response body to None
In the context of DELETE, it's more than likely than the response will
be empty. In such a case, setting response.body to None will fail.
Change-Id: I29fde6c448c935c40c768376a15e83337b951898
-rw-r--r-- | pecan/core.py | 2 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/pecan/core.py b/pecan/core.py index 0aad76a..15d47f7 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -539,7 +539,7 @@ class Pecan(object): # set the body content if isinstance(result, six.text_type): resp.text = result - else: + elif result: resp.body = result # set the content type diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index e5ec6af..d9808a0 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -33,6 +33,23 @@ class TestAppRoot(PecanTestCase): assert app.root and isinstance(app.root, SampleRootController) +class TestEmptyContent(PecanTestCase): + @property + def app_(self): + class RootController(object): + @expose() + def index(self): + pass + + return TestApp(Pecan(RootController())) + + def test_empty_index(self): + r = self.app_.get('/') + self.assertEqual(r.status_int, 200) + self.assertEqual(r.headers['Content-Length'], '0') + self.assertEqual(len(r.body), 0) + + class TestIndexRouting(PecanTestCase): @property |