diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 7085dc8f5..b50551c84 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -2560,6 +2560,87 @@ StickTable class {"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 a96b5c6b3..916530658 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7618,6 +7618,27 @@ void hlua_init(void) lua_setglobal(gL.T, "core"); + /* + * + * 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