Skip to content
Snippets Groups Projects
Unverified Commit 2901f543 authored by Erik Johnston's avatar Erik Johnston Committed by GitHub
Browse files

Fix missing CORS headers on OPTION responses (#7560)

Broke in #7534.
parent e5c67d04
No related branches found
No related tags found
No related merge requests found
All endpoints now respond with a 200 OK for `OPTIONS` requests.
\ No newline at end of file
......@@ -452,7 +452,7 @@ class OptionsResource(resource.Resource):
code, response_json_object = _options_handler(request)
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):
......
......@@ -203,12 +203,40 @@ class OptionsResourceTests(unittest.TestCase):
self.assertEqual(channel.result["code"], b"200")
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):
"""An OPTIONS requests to an known URL still returns 200 OK."""
channel = self._make_request(b"OPTIONS", b"/res/")
self.assertEqual(channel.result["code"], b"200")
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):
"""A non-OPTIONS request to an unknown URL should 404."""
channel = self._make_request(b"GET", b"/foo/")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment