fix(routing): Default OPTIONS responder should return 200, not 204 (#993)

Fixes #796
This commit is contained in:
Kurt Griffiths
2017-01-27 08:43:33 -07:00
committed by John Vrbanac
parent 673bb2e136
commit 8176dc5952
3 changed files with 8 additions and 7 deletions

View File

@@ -17,7 +17,7 @@
from falcon.errors import HTTPBadRequest
from falcon.errors import HTTPMethodNotAllowed
from falcon.errors import HTTPNotFound
from falcon.status_codes import HTTP_204
from falcon.status_codes import HTTP_200
def path_not_found(req, resp, **kwargs):
@@ -56,7 +56,7 @@ def create_default_options(allowed_methods):
allowed = ', '.join(allowed_methods)
def on_options(req, resp, **kwargs):
resp.status = HTTP_204
resp.status = HTTP_200
resp.set_header('Allow', allowed)
resp.set_header('Content-Length', '0')

View File

@@ -210,7 +210,7 @@ class TestHooks(testing.TestCase):
# Decorator should not affect the default on_options responder
result = self.simulate_options('/wrapped')
self.assertEqual(result.status_code, 204)
self.assertEqual(result.status_code, 200)
self.assertFalse(result.text)
def test_wrapped_resource_with_hooks_aware_of_resource(self):
@@ -230,5 +230,5 @@ class TestHooks(testing.TestCase):
# Decorator should not affect the default on_options responder
result = self.simulate_options('/wrapped_aware')
self.assertEqual(result.status_code, 204)
self.assertEqual(result.status_code, 200)
self.assertFalse(result.text)

View File

@@ -89,6 +89,7 @@ class MiscResource(object):
pass
def on_options(self, req, resp):
# NOTE(kgriffs): The default responder returns 200
resp.status = falcon.HTTP_204
# NOTE(kgriffs): This is incorrect, but only return GET so
@@ -192,16 +193,16 @@ class TestHttpMethodRouting(testing.TestBase):
self.assertThat(headers, Contains(allow_header))
def test_on_options(self):
def test_default_on_options(self):
self.simulate_request('/things/84/stuff/65', method='OPTIONS')
self.assertEqual(self.srmock.status, falcon.HTTP_204)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
headers = self.srmock.headers
allow_header = ('allow', 'GET, HEAD, PUT')
self.assertThat(headers, Contains(allow_header))
def test_default_on_options(self):
def test_on_options(self):
self.simulate_request('/misc', method='OPTIONS')
self.assertEqual(self.srmock.status, falcon.HTTP_204)