MINOR: lua: Create the global 'act' object to register all action return codes
ACT_RET_* code are now available from lua scripts. The gloabl object "act" is
used to register these codes as constant. Now, lua actions can return any of
following codes :
* act.CONTINUE for ACT_RET_CONT
* act.STOP for ACT_RET_STOP
* act.YIELD for ACT_RET_YIELD
* act.ERROR for ACT_RET_ERR
* act.DONE for ACT_RET_DONE
* act.DENY for ACT_RET_DENY
* act.ABORT for ACT_RET_ABRT
* act.INVALID for ACT_RET_INV
For instance, following script denied all requests :
core.register_action("deny", { "http-req" }, function (txn)
return act.DENY
end)
Thus "http-request lua.deny" do exactly the same than "http-request deny".
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 7085dc8..b50551c 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -2560,6 +2560,87 @@
{"gpc0", "gt", 30}, {"gpc1", "gt", 20}}, {"conn_rate", "le", 10}
}
+.. _action_class:
+
+Action class
+=============
+
+.. js:class:: Act
+
+ **context**: action
+
+ This class contains all return codes an action may return. It is the lua
+ equivalent to HAProxy "ACT_RET_*" code.
+
+.. code-block:: lua
+
+ core.register_action("deny", { "http-req" }, function (txn)
+ return act.DENY
+ end)
+..
+.. js:attribute:: act.CONTINUE
+
+ This attribute is an integer (0). It instructs HAProxy to continue the current
+ ruleset processing on the message. It is the default return code for a lua
+ action.
+
+ :returns: integer
+
+.. js:attribute:: act.STOP
+
+ This attribute is an integer (1). It instructs HAProxy to stop the current
+ ruleset processing on the message.
+
+.. js:attribute:: act.YIELD
+
+ This attribute is an integer (2). It instructs HAProxy to temporarily pause
+ the message processing. It will be resumed later on the same rule. The
+ corresponding lua script is re-executed for the start.
+
+.. js:attribute:: act.ERROR
+
+ This attribute is an integer (3). It triggers an internal errors The message
+ processing is stopped and the transaction is terminated. For HTTP streams, an
+ HTTP 500 error is returned to the client.
+
+ :returns: integer
+
+.. js:attribute:: act.DONE
+
+ This attribute is an integer (4). It instructs HAProxy to stop the message
+ processing.
+
+ :returns: integer
+
+.. js:attribute:: act.DENY
+
+ This attribute is an integer (5). It denies the current message. The message
+ processing is stopped and the transaction is terminated. For HTTP streams, an
+ HTTP 403 error is returned to the client if the deny is returned during the
+ request analysis. During the response analysis, an HTTP 502 error is returned
+ and the server response is discarded.
+
+ :returns: integer
+
+.. js:attribute:: act.ABORT
+
+ This attribute is an integer (6). It aborts the current message. The message
+ processing is stopped and the transaction is terminated. For HTTP streams,
+ HAproxy assumes a response was already sent to the client. From the Lua
+ actions point of view, when this code is used, the transaction is terminated
+ with no reply.
+
+ :returns: integer
+
+.. js:attribute:: act.INVALID
+
+ This attribute is an integer (7). It triggers an internal errors. The message
+ processing is stopped and the transaction is terminated. For HTTP streams, an
+ HTTP 400 error is returned to the client if the error is returned during the
+ request analysis. During the response analysis, an HTTP 502 error is returned
+ and the server response is discarded.
+
+ :returns: integer
External Lua libraries
======================
diff --git a/src/hlua.c b/src/hlua.c
index a96b5c6..9165306 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -7620,6 +7620,27 @@
/*
*
+ * Create "act" object.
+ *
+ */
+
+ /* This table entry is the object "act" base. */
+ lua_newtable(gL.T);
+
+ /* push action return constants */
+ hlua_class_const_int(gL.T, "CONTINUE", ACT_RET_CONT);
+ hlua_class_const_int(gL.T, "STOP", ACT_RET_STOP);
+ hlua_class_const_int(gL.T, "YIELD", ACT_RET_YIELD);
+ hlua_class_const_int(gL.T, "ERROR", ACT_RET_ERR);
+ hlua_class_const_int(gL.T, "DONE", ACT_RET_DONE);
+ hlua_class_const_int(gL.T, "DENY", ACT_RET_DENY);
+ hlua_class_const_int(gL.T, "ABORT", ACT_RET_ABRT);
+ hlua_class_const_int(gL.T, "INVALID", ACT_RET_INV);
+
+ lua_setglobal(gL.T, "act");
+
+ /*
+ *
* Register class Map
*
*/