From 5ef11c505accc40fc0a0b655dc5fdbdb079460cd Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Sat, 4 Jun 2016 06:53:05 +0530 Subject: [PATCH] fix(Response): Sets default OPTIONS responder Content-Length to 0 (#801) * fix(Response): Sets default OPTIONS responder Content-Length to 0 Closes #796 * test(Response): Added test to check default content-length header for OPTIONS Request It checks that the content-length header for options request is 0. Closes #796 --- falcon/responders.py | 1 + tests/test_headers.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/falcon/responders.py b/falcon/responders.py index b5f6186..34da807 100644 --- a/falcon/responders.py +++ b/falcon/responders.py @@ -58,5 +58,6 @@ def create_default_options(allowed_methods): def on_options(req, resp, **kwargs): resp.status = HTTP_204 resp.set_header('Allow', allowed) + resp.set_header('Content-Length', '0') return on_options diff --git a/tests/test_headers.py b/tests/test_headers.py index 8880992..838755d 100644 --- a/tests/test_headers.py +++ b/tests/test_headers.py @@ -534,6 +534,12 @@ class TestHeaders(testing.TestCase): self._check_link_header(resource, expected_value) + def test_content_length_options(self): + result = self.simulate_options() + + content_length = '0' + self.assertEqual(result.headers['Content-Length'], content_length) + # ---------------------------------------------------------------------- # Helpers # ----------------------------------------------------------------------