From: Christopher Faulet Date: Wed, 26 Feb 2020 16:14:08 +0000 (+0100) Subject: MINOR: filters/lua: Add request and response HTTP messages in the lua TXN X-Git-Tag: v2.5-dev4~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78c35471f8f531dd31d3b2b845d59697f195a160;p=thirdparty%2Fhaproxy.git MINOR: filters/lua: Add request and response HTTP messages in the lua TXN When a lua TXN is created from a filter context, the request and the response HTTP message objects are accessible from ".http_req" and ".http_res" fields. For an HTTP proxy, these objects are always defined. Otherwise, for a TCP proxy, no object is created and nil is used instead. From any other context (action or sample fetch), these fields don't exist. --- diff --git a/src/hlua.c b/src/hlua.c index c1a578ed4e..cd539d05f4 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -5915,7 +5915,7 @@ __LJMP static struct http_msg *hlua_checkhttpmsg(lua_State *L, int ud) /* Creates and pushes on the stack a HTTP object according with a current TXN. */ -static __maybe_unused int hlua_http_msg_new(lua_State *L, struct http_msg *msg) +static int hlua_http_msg_new(lua_State *L, struct http_msg *msg) { /* Check stack size. */ if (!lua_checkstack(L, 3)) @@ -7086,6 +7086,32 @@ static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir lua_pushnil(L); lua_rawset(L, -3); + if ((htxn->flags & HLUA_TXN_CTX_MASK) == HLUA_TXN_FLT_CTX) { + /* HTTPMessage object are created when a lua TXN is created from + * a filter context only + */ + + /* Creates the HTTP-Request object is the current proxy allows http. */ + lua_pushstring(L, "http_req"); + if (p->mode == PR_MODE_HTTP) { + if (!hlua_http_msg_new(L, &s->txn->req)) + return 0; + } + else + lua_pushnil(L); + lua_rawset(L, -3); + + /* Creates the HTTP-Response object is the current proxy allows http. */ + lua_pushstring(L, "http_res"); + if (p->mode == PR_MODE_HTTP) { + if (!hlua_http_msg_new(L, &s->txn->rsp)) + return 0; + } + else + lua_pushnil(L); + lua_rawset(L, -3); + } + /* Pop a class sesison metatable and affect it to the userdata. */ lua_rawgeti(L, LUA_REGISTRYINDEX, class_txn_ref); lua_setmetatable(L, -2);