diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-05-22 09:30:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 09:30:07 -0400 |
commit | 4429764c9f00bd1d266f08e08a20daac1b849d46 (patch) | |
tree | 6b590b75e300860d8f9fbab36f47326dfed7fe38 /synapse/http/server.py | |
parent | Add ability to wait for replication streams (#7542) (diff) | |
download | synapse-4429764c9f00bd1d266f08e08a20daac1b849d46.tar.xz |
Return 200 OK for all OPTIONS requests (#7534)
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r-- | synapse/http/server.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index 042a605198..33fcfbea6e 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -350,9 +350,6 @@ class JsonResource(HttpServer, resource.Resource): register_paths, so will return (possibly via Deferred) either None, or a tuple of (http code, response body). """ - if request.method == b"OPTIONS": - return _options_handler, "options_request_handler", {} - request_path = request.path.decode("ascii") # Loop through all the registered callbacks to check if the method @@ -448,6 +445,26 @@ class RootRedirect(resource.Resource): return resource.Resource.getChild(self, name, request) +class OptionsResource(resource.Resource): + """Responds to OPTION requests for itself and all children.""" + + def render_OPTIONS(self, request): + code, response_json_object = _options_handler(request) + + return respond_with_json( + request, code, response_json_object, send_cors=False, canonical_json=False, + ) + + def getChildWithDefault(self, path, request): + if request.method == b"OPTIONS": + return self # select ourselves as the child to render + return resource.Resource.getChildWithDefault(self, path, request) + + +class RootOptionsRedirectResource(OptionsResource, RootRedirect): + pass + + def respond_with_json( request, code, |