From e11515be96af93e4a2f34cb4b7f260c11f439c9a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 7 Aug 2018 15:21:26 +0100 Subject: [PATCH] [Feature] Support gathering HTTP body from fragments in lua_http --- src/lua/lua_http.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 87244dd55..b3d4350f5 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -553,6 +553,35 @@ lua_http_request (lua_State *L) if (t) { body = rspamd_fstring_new_init (t->start, t->len); } + else { + return luaL_error (L, "invalid body argument"); + } + } + else if (lua_type (L, -1) == LUA_TTABLE) { + body = rspamd_fstring_new (); + + for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) { + if (lua_type (L, -1) == LUA_TSTRING) { + lua_body = lua_tolstring (L, -1, &bodylen); + body = rspamd_fstring_append (body, lua_body, bodylen); + } + else if (lua_type (L, -1) == LUA_TUSERDATA) { + t = lua_check_text (L, -1); + + if (t) { + body = rspamd_fstring_append (body, t->start, t->len); + } + else { + return luaL_error (L, "invalid body argument"); + } + } + else { + return luaL_error (L, "invalid body argument"); + } + } + } + else { + return luaL_error (L, "invalid body argument"); } lua_pop (L, 1); -- 2.39.5