mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
parent
e5c67d04db
commit
2901f54359
1
changelog.d/7560.misc
Normal file
1
changelog.d/7560.misc
Normal file
@ -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)
|
||||
|
||||
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/")
|
||||
|
Loading…
Reference in New Issue
Block a user