diff options
author | Amber Brown <hawkowl@atleastfornow.net> | 2019-07-03 04:01:28 +1000 |
---|---|---|
committer | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2019-07-02 19:01:28 +0100 |
commit | 0ee9076ffe40140db5e86763af077efbdb5d86b0 (patch) | |
tree | acab7d2c00d9daeaf45e7c5eeee9e6cf1f8f60af /synapse/http | |
parent | tweak changelog (diff) | |
download | synapse-0ee9076ffe40140db5e86763af077efbdb5d86b0.tar.xz |
Fix media repo breaking (#5593)
Diffstat (limited to 'synapse/http')
-rw-r--r-- | synapse/http/server.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index f067c163c1..d993161a3e 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -65,8 +65,8 @@ def wrap_json_request_handler(h): The handler method must have a signature of "handle_foo(self, request)", where "request" must be a SynapseRequest. - The handler must return a deferred. If the deferred succeeds we assume that - a response has been sent. If the deferred fails with a SynapseError we use + The handler must return a deferred or a coroutine. If the deferred succeeds + we assume that a response has been sent. If the deferred fails with a SynapseError we use it to send a JSON response with the appropriate HTTP reponse code. If the deferred fails with any other type of error we send a 500 reponse. """ @@ -353,16 +353,22 @@ class DirectServeResource(resource.Resource): """ Render the request, using an asynchronous render handler if it exists. """ - render_callback_name = "_async_render_" + request.method.decode("ascii") + async_render_callback_name = "_async_render_" + request.method.decode("ascii") - if hasattr(self, render_callback_name): - # Call the handler - callback = getattr(self, render_callback_name) - defer.ensureDeferred(callback(request)) + # Try and get the async renderer + callback = getattr(self, async_render_callback_name, None) - return NOT_DONE_YET - else: - super().render(request) + # No async renderer for this request method. + if not callback: + return super().render(request) + + resp = callback(request) + + # If it's a coroutine, turn it into a Deferred + if isinstance(resp, types.CoroutineType): + defer.ensureDeferred(resp) + + return NOT_DONE_YET def _options_handler(request): |