From: Thierry FOURNIER Date: Mon, 12 Feb 2018 13:46:54 +0000 (+0100) Subject: DOC: lua: new prototype for function "register_action()" X-Git-Tag: v1.9-dev1~422 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5d11c6b3392d548c45d617f132a1269d4d021fa;p=thirdparty%2Fhaproxy.git DOC: lua: new prototype for function "register_action()" This patch should be backported to version 1.8. --- diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 7fe609fc90..e7aa425d95 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -443,7 +443,7 @@ Core class configuration file. Each entry of the proxies array is an object of type :ref:`proxy_class` -.. js:function:: core.register_action(name, actions, func) +.. js:function:: core.register_action(name, actions, func [, nb_args]) **context**: body @@ -455,18 +455,22 @@ Core class :param table actions: is a table of string describing the HAProxy actions who want to register to. The expected actions are 'tcp-req', 'tcp-res', 'http-req' or 'http-res'. + :param integer nb_args: is the expected number of argument for the action. + By default the value is 0. :param function func: is the Lua function called to work as converter. The prototype of the Lua function used as argument is: .. code-block:: lua - function(txn) + function(txn [, arg1 [, arg2]]) .. * **txn** (:ref:`txn_class`): this is a TXN object used for manipulating the current request or TCP stream. + * **argX**: this is argument provided throught the HAProxy configuration file. + Here, an exemple of action registration. the action juste send an 'Hello world' in the logs. @@ -488,7 +492,26 @@ Core class frontend http_frt mode http http-request lua.hello-world +.. + + A second example using aruments + +.. code-block:: lua + + function hello_world(txn, arg) + txn:Info("Hello world for " .. arg) + end + core.register_action("hello-world", { "tcp-req", "http-req" }, hello_world, 2) +.. + This example code is used in HAproxy configuration like this: + +:: + + frontend tcp_frt + mode tcp + tcp-request content lua.hello-world everybody +.. .. js:function:: core.register_converters(name, func) **context**: body