From 6a9ba853221e42adcdb2aead8c59f898e2769ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gross?= Date: Wed, 13 Sep 2023 05:51:59 -0400 Subject: [PATCH] MINOR: hlua: Add support for the "http-after-res" action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- doc/lua-api/index.rst | 2 +- src/hlua.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index bab55228c..8a29bc5b5 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 e125eff82..de32c524e 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))); }