]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: Add support for the "http-after-res" action
authorSébastien Gross <sgross@haproxy.com>
Wed, 13 Sep 2023 09:51:59 +0000 (05:51 -0400)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 21 Sep 2023 14:31:20 +0000 (16:31 +0200)
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>
doc/lua-api/index.rst
src/hlua.c

index bab55228cacabeadfe149a589f402e17f9492972..8a29bc5b5fb8e35ab8f2ac5ef173ceaa437536b7 100644 (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.
index e125eff828f971866ad9ddadcd83199fbf7c166d..de32c524e3872e101a8653d77067a670b6dc0399 100644 (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)));
                }