From: Sébastien Gross Date: Wed, 13 Sep 2023 09:51:59 +0000 (-0400) Subject: MINOR: hlua: Add support for the "http-after-res" action X-Git-Tag: v2.9-dev6~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a9ba853221e42adcdb2aead8c59f898e2769ab0;p=thirdparty%2Fhaproxy.git 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 --- diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index bab55228ca..8a29bc5b5f 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -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. diff --git a/src/hlua.c b/src/hlua.c index e125eff828..de32c524e3 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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))); }