]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Support gathering HTTP body from fragments in lua_http
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Aug 2018 14:21:26 +0000 (15:21 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Aug 2018 14:21:26 +0000 (15:21 +0100)
src/lua/lua_http.c

index 87244dd5524eb4480859f9acf73c1dfcac859074..b3d4350f5fc3b303503b13cf2d660b70cb675ce7 100644 (file)
@@ -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);