]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a sample custom Lua web handler to the documentation
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 5 Nov 2020 14:38:38 +0000 (15:38 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 5 Nov 2020 14:38:38 +0000 (15:38 +0100)
pdns/dnsdistdist/docs/reference/config.rst

index 084024c50f500f62726a42e999f9c9f8a0c78239..24eac8bceaf4b37cf7949527f3db4b17f26ed228 100644 (file)
@@ -362,6 +362,26 @@ Webserver configuration
   - ...
   But not queries for /foobar or /foo/bar.
 
+  A sample handler function could be:
+
+  .. code-block:: lua
+
+    function customHTTPHandler(req, resp)
+      local get = req.getvars
+      local headers = req.headers
+
+      if req.path ~= '/foo' or req.version ~= 11 or req.method ~= 'GET' or get['param'] ~= '42' or headers['customheader'] ~= 'foobar' then
+        resp.status = 500
+        return
+      end
+
+      resp.status = 200
+      resp.body = 'It works!'
+      resp.headers = { ['Foo']='Bar'}
+    end
+
+    registerWebHandler('/foo', customHTTPHandler)
+
   :param str path: Path to register the handler for.
   :param function handler: The Lua function to register.