From: Remi Gacogne Date: Thu, 5 Nov 2020 14:38:38 +0000 (+0100) Subject: dnsdist: Add a sample custom Lua web handler to the documentation X-Git-Tag: dnsdist-1.6.0-alpha0~13^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6c46eb437220e1ec019a6380d47cb53b5fccf10;p=thirdparty%2Fpdns.git dnsdist: Add a sample custom Lua web handler to the documentation --- diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 084024c50f..24eac8bcea 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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.