mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-08 08:14:56 -04:00
Respect the @cancellable
flag for RestServlet
s and BaseFederationServlet
s (#12699)
Both `RestServlet`s and `BaseFederationServlet`s register their handlers with `HttpServer.register_paths` / `JsonResource.register_paths`. Update `JsonResource` to respect the `@cancellable` flag on handlers registered in this way. Although `ReplicationEndpoint` also registers itself using `register_paths`, it does not pass the handler method that would have the `@cancellable` flag directly, and so needs separate handling. Signed-off-by: Sean Quah <seanq@element.io>
This commit is contained in:
parent
dffecade7d
commit
9d8e380d2e
6 changed files with 191 additions and 2 deletions
|
@ -314,6 +314,9 @@ class HttpServer(Protocol):
|
|||
If the regex contains groups these gets passed to the callback via
|
||||
an unpacked tuple.
|
||||
|
||||
The callback may be marked with the `@cancellable` decorator, which will
|
||||
cause request processing to be cancelled when clients disconnect early.
|
||||
|
||||
Args:
|
||||
method: The HTTP method to listen to.
|
||||
path_patterns: The regex used to match requests.
|
||||
|
@ -544,6 +547,8 @@ class JsonResource(DirectServeJsonResource):
|
|||
async def _async_render(self, request: SynapseRequest) -> Tuple[int, Any]:
|
||||
callback, servlet_classname, group_dict = self._get_handler_for_request(request)
|
||||
|
||||
request.is_render_cancellable = is_method_cancellable(callback)
|
||||
|
||||
# Make sure we have an appropriate name for this handler in prometheus
|
||||
# (rather than the default of JsonResource).
|
||||
request.request_metrics.name = servlet_classname
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue