mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-03 02:32:03 +00:00
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".
This commit is contained in:
parent
7716cdf450
commit
0f3c8907c3
@ -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
|
||||
======================
|
||||
|
21
src/hlua.c
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user