MINOR: hlua: Add support for the "http-after-res" action

This commit introduces support for the "http-after-res" action in
hlua, enabling the invocation of a Lua function in a
"http-after-response" rule. With this enhancement, a Lua action can be
registered using the "http-after-res" action type:

    core.register_action('myaction', {'http-after-res'}, myaction)

A new "lua.myaction" is created and can be invoked in a
"http-after-response" rule:

    http-after-response lua.myaction

This addition provides greater flexibility and extensibility in
handling post-response actions using Lua.

This commit depends on:
 - 4457783 ("MINOR: http_ana: position the FINAL flag for http_after_res execution")

Signed-off-by: Sébastien Gross <sgross@haproxy.com>
This commit is contained in:
Sébastien Gross 2023-09-13 05:51:59 -04:00 committed by Christopher Faulet
parent 95c4d24825
commit 6a9ba85322
2 changed files with 7 additions and 2 deletions

View File

@ -493,7 +493,7 @@ Core class
:param string name: is the name of the action.
:param table actions: is a table of string describing the HAProxy actions
facilities where to expose the new action. Expected facilities are:
'tcp-req', 'tcp-res', 'http-req' or 'http-res'.
'tcp-req', 'tcp-res', 'http-req', 'http-res', 'http-after-res'.
:param function func: is the Lua function called to work as an action.
:param integer nb_args: is the expected number of argument for the action.
By default the value is 0.

View File

@ -10984,6 +10984,8 @@ __LJMP static int hlua_register_action(lua_State *L)
akw = action_http_req_custom(trash->area);
} else if (strcmp(lua_tostring(L, -1), "http-res") == 0) {
akw = action_http_res_custom(trash->area);
} else if (strcmp(lua_tostring(L, -1), "http-after-res") == 0) {
akw = action_http_after_res_custom(trash->area);
} else {
akw = NULL;
}
@ -11043,6 +11045,8 @@ __LJMP static int hlua_register_action(lua_State *L)
http_req_keywords_register(akl);
else if (strcmp(lua_tostring(L, -1), "http-res") == 0)
http_res_keywords_register(akl);
else if (strcmp(lua_tostring(L, -1), "http-after-res") == 0)
http_after_res_keywords_register(akl);
else {
release_hlua_function(fcn);
hlua_unref(L, ref);
@ -11050,7 +11054,8 @@ __LJMP static int hlua_register_action(lua_State *L)
ha_free((char **)&(akl->kw[0].kw));
ha_free(&akl);
WILL_LJMP(luaL_error(L, "Lua action environment '%s' is unknown. "
"'tcp-req', 'tcp-res', 'http-req' or 'http-res' "
"'tcp-req', 'tcp-res', 'http-req', 'http-res' "
"or 'http-after-res' "
"are expected.", lua_tostring(L, -1)));
}