parent
e5c67d04db
commit
2901f54359
|
@ -0,0 +1 @@
|
||||||
|
All endpoints now respond with a 200 OK for `OPTIONS` requests.
|
|
@ -452,7 +452,7 @@ class OptionsResource(resource.Resource):
|
||||||
code, response_json_object = _options_handler(request)
|
code, response_json_object = _options_handler(request)
|
||||||
|
|
||||||
return respond_with_json(
|
return respond_with_json(
|
||||||
request, code, response_json_object, send_cors=False, canonical_json=False,
|
request, code, response_json_object, send_cors=True, canonical_json=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def getChildWithDefault(self, path, request):
|
def getChildWithDefault(self, path, request):
|
||||||
|
|
|
@ -203,12 +203,40 @@ class OptionsResourceTests(unittest.TestCase):
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
self.assertEqual(channel.result["body"], b"{}")
|
self.assertEqual(channel.result["body"], b"{}")
|
||||||
|
|
||||||
|
# Ensure the correct CORS headers have been added
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Origin"),
|
||||||
|
"has CORS Origin header",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Methods"),
|
||||||
|
"has CORS Methods header",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Headers"),
|
||||||
|
"has CORS Headers header",
|
||||||
|
)
|
||||||
|
|
||||||
def test_known_options_request(self):
|
def test_known_options_request(self):
|
||||||
"""An OPTIONS requests to an known URL still returns 200 OK."""
|
"""An OPTIONS requests to an known URL still returns 200 OK."""
|
||||||
channel = self._make_request(b"OPTIONS", b"/res/")
|
channel = self._make_request(b"OPTIONS", b"/res/")
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
self.assertEqual(channel.result["body"], b"{}")
|
self.assertEqual(channel.result["body"], b"{}")
|
||||||
|
|
||||||
|
# Ensure the correct CORS headers have been added
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Origin"),
|
||||||
|
"has CORS Origin header",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Methods"),
|
||||||
|
"has CORS Methods header",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
channel.headers.hasHeader(b"Access-Control-Allow-Headers"),
|
||||||
|
"has CORS Headers header",
|
||||||
|
)
|
||||||
|
|
||||||
def test_unknown_request(self):
|
def test_unknown_request(self):
|
||||||
"""A non-OPTIONS request to an unknown URL should 404."""
|
"""A non-OPTIONS request to an unknown URL should 404."""
|
||||||
channel = self._make_request(b"GET", b"/foo/")
|
channel = self._make_request(b"GET", b"/foo/")
|
||||||
|
|
Loading…
Reference in New Issue