def register(self, http_server: HttpServer) -> None: """Called by the server to register this as a handler to the appropriate path. """ url_args = list(self.PATH_ARGS) method = self.METHOD if self.CACHE and is_method_cancellable(self._handle_request): raise Exception( f"{self.__class__.__name__} has been marked as cancellable, but CACHE " "is set. The cancellable flag would have no effect.") if self.CACHE: url_args.append("txn_id") args = "/".join("(?P<%s>[^/]+)" % (arg, ) for arg in url_args) pattern = re.compile("^/_synapse/replication/%s/%s$" % (self.NAME, args)) http_server.register_paths( method, [pattern], self._check_auth_and_handle, self.__class__.__name__, )
def register(self, json_resource: HttpServer) -> None: PATTERN = "/send_server_notice" json_resource.register_paths("POST", admin_patterns(PATTERN + "$"), self.on_POST, self.__class__.__name__) json_resource.register_paths( "PUT", admin_patterns(PATTERN + "/(?P<txn_id>[^/]*)$"), self.on_PUT, self.__class__.__name__, )
def register(self, http_server: HttpServer) -> None: http_server.register_paths( "POST", client_patterns(self.PATTERN + "$", releases=()), self.on_PUT_or_POST, self.__class__.__name__, ) http_server.register_paths( "PUT", client_patterns(self.PATTERN + "/(?P<txn_id>[^/]*)$", releases=()), self.on_PUT, self.__class__.__name__, )
def register(self, http_server: HttpServer) -> None: super().register(http_server) if self._msc2858_enabled: # expose additional endpoint for MSC2858 support http_server.register_paths( "GET", client_patterns( "/org.matrix.msc2858/login/sso/redirect/(?P<idp_id>[A-Za-z0-9_.~-]+)$", releases=(), unstable=True, ), self.on_GET, self.__class__.__name__, )
def register(self, http_server: HttpServer) -> None: # /room/$roomid/state/$eventtype no_state_key = "/rooms/(?P<room_id>[^/]*)/state/(?P<event_type>[^/]*)$" # /room/$roomid/state/$eventtype/$statekey state_key = ("/rooms/(?P<room_id>[^/]*)/state/" "(?P<event_type>[^/]*)/(?P<state_key>[^/]*)$") http_server.register_paths( "GET", client_patterns(state_key, v1=True), self.on_GET, self.__class__.__name__, ) http_server.register_paths( "PUT", client_patterns(state_key, v1=True), self.on_PUT, self.__class__.__name__, ) http_server.register_paths( "GET", client_patterns(no_state_key, v1=True), self.on_GET_no_state_key, self.__class__.__name__, ) http_server.register_paths( "PUT", client_patterns(no_state_key, v1=True), self.on_PUT_no_state_key, self.__class__.__name__, )
def register(self, http_server: HttpServer) -> None: """Register this servlet with the given HTTP server.""" patterns = getattr(self, "PATTERNS", None) if patterns: for method in ("GET", "PUT", "POST", "DELETE"): if hasattr(self, "on_%s" % (method, )): servlet_classname = self.__class__.__name__ method_handler = getattr(self, "on_%s" % (method, )) http_server.register_paths(method, patterns, method_handler, servlet_classname) else: raise NotImplementedError("RestServlet must register something.")
def register(self, server: HttpServer) -> None: pattern = re.compile("^" + self.PREFIX + self.PATH + "$") for method in ("GET", "PUT", "POST"): code = getattr(self, "on_%s" % (method), None) if code is None: continue server.register_paths( method, (pattern, ), self._wrap(code), self.__class__.__name__, )
def register(self, server: HttpServer) -> None: pattern = re.compile("^" + self.PREFIX + self.PATH + "$") for method in ("GET", "PUT", "POST"): code = getattr(self, "on_%s" % (method), None) if code is None: continue if is_method_cancellable(code): # The wrapper added by `self._wrap` will inherit the cancellable flag, # but the wrapper itself does not support cancellation yet. # Once resolved, the cancellation tests in # `tests/federation/transport/server/test__base.py` can be re-enabled. raise Exception( f"{self.__class__.__name__}.on_{method} has been marked as " "cancellable, but federation servlets do not support cancellation " "yet.") server.register_paths( method, (pattern, ), self._wrap(code), self.__class__.__name__, )
def register_txn_path( servlet: RestServlet, regex_string: str, http_server: HttpServer, with_get: bool = False, ) -> None: """Registers a transaction-based path. This registers two paths: PUT regex_string/$txnid POST regex_string Args: regex_string: The regex string to register. Must NOT have a trailing $ as this string will be appended to. http_server: The http_server to register paths with. with_get: True to also register respective GET paths for the PUTs. """ on_POST = getattr(servlet, "on_POST", None) on_PUT = getattr(servlet, "on_PUT", None) if on_POST is None or on_PUT is None: raise RuntimeError( "on_POST and on_PUT must exist when using register_txn_path") http_server.register_paths( "POST", client_patterns(regex_string + "$", v1=True), on_POST, servlet.__class__.__name__, ) http_server.register_paths( "PUT", client_patterns(regex_string + "/(?P<txn_id>[^/]*)$", v1=True), on_PUT, servlet.__class__.__name__, ) on_GET = getattr(servlet, "on_GET", None) if with_get: if on_GET is None: raise RuntimeError( "register_txn_path called with with_get = True, but no on_GET method exists" ) http_server.register_paths( "GET", client_patterns(regex_string + "/(?P<txn_id>[^/]*)$", v1=True), on_GET, servlet.__class__.__name__, )