]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make response handler management more flexible
authorMichał Kępień <michal@isc.org>
Fri, 11 Apr 2025 14:14:57 +0000 (09:14 -0500)
committerMichał Kępień <michal@isc.org>
Fri, 11 Apr 2025 14:14:57 +0000 (09:14 -0500)
Extend AsyncDnsServer.install_response_handler() so that the provided
response handler can be inserted at the beginning of the handler list.
This enables installing a response handler that takes priority over all
previously installed handlers.

Add a new method, AsyncDnsServer.uninstall_response_handler(), which
enables removing a previously installed response handler.

Together, these two methods provide full control over the response
handler list at runtime.

bin/tests/system/isctest/asyncserver.py

index fb5f2c21c34da50ca3dd178f658c4b00948583de..0ace0f277fed005abecc56760c1ad88b63e54c74 100644 (file)
@@ -532,15 +532,31 @@ class AsyncDnsServer(AsyncServer):
         if load_zones:
             self._load_zones()
 
-    def install_response_handler(self, handler: ResponseHandler) -> None:
+    def install_response_handler(
+        self, handler: ResponseHandler, prepend: bool = False
+    ) -> None:
         """
-        Add a response handler which will be used to handle matching queries.
+        Add a response handler that will be used to handle matching queries.
 
         Response handlers can modify, replace, or suppress the answers prepared
         from zone file contents.
+
+        The provided handler is installed at the end of the response handler
+        list unless `prepend` is set to True, in which case it is installed at
+        the beginning of the response handler list.
         """
         logging.info("Installing response handler: %s", handler)
-        self._response_handlers.append(handler)
+        if prepend:
+            self._response_handlers.insert(0, handler)
+        else:
+            self._response_handlers.append(handler)
+
+    def uninstall_response_handler(self, handler: ResponseHandler) -> None:
+        """
+        Remove the specified handler from the list of response handlers.
+        """
+        logging.info("Uninstalling response handler: %s", handler)
+        self._response_handlers.remove(handler)
 
     def _load_zones(self) -> None:
         for entry in os.scandir():