diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-22 15:50:47 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-22 15:51:05 +0000 |
commit | f5e540efcbb10cc3e260997ef3460093e8bd5152 (patch) | |
tree | 21c51e6d0c063b98919c00766388bbfcdf6db4e0 /src/lua/lua_task.c | |
parent | 5843aaf26d36fe24c1d0390b2140c61c7dc0eefc (diff) | |
download | rspamd-f5e540efcbb10cc3e260997ef3460093e8bd5152.tar.gz rspamd-f5e540efcbb10cc3e260997ef3460093e8bd5152.zip |
[Minor] Lua_task: Simplify has_header method
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index c0d5c85e0..9cc037796 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -353,10 +353,10 @@ LUA_FUNCTION_DEF (task, get_header); /*** * @method task:has_header(name[, case_sensitive]) * Get decoded value of a header specified with optional case_sensitive flag. - * By default headers are searched in caseless matter. + * By default headers are searched in the case insensitive matter. * @param {string} name name of header to get * @param {boolean} case_sensitive case sensitiveness flag to search for a header - * @return {boolean},{number} true if header exists, the second value is number of headers with this name + * @return {boolean} true if header exists */ LUA_FUNCTION_DEF (task, has_header); /*** @@ -2828,8 +2828,7 @@ rspamd_lua_push_header_array (lua_State *L, if (rh == NULL) { if (how == RSPAMD_TASK_HEADER_PUSH_HAS) { lua_pushboolean (L, false); - lua_pushnumber (L, 0); - nret = 2; + nret = 1; } else if (how == RSPAMD_TASK_HEADER_PUSH_COUNT) { lua_pushnumber (L, 0); @@ -2864,17 +2863,23 @@ rspamd_lua_push_header_array (lua_State *L, lua_pushinteger (L, i); } else if (how == RSPAMD_TASK_HEADER_PUSH_HAS) { - i = 0; - nret = 2; - - DL_FOREACH (rh, cur) { - if (!strong || strcmp (name, cur->name) == 0) { - i++; + nret = 1; + bool found = false; + + if (strong) { + /* We still have to check all headers in the chain */ + DL_FOREACH (rh, cur) { + if (strcmp (name, cur->name) == 0) { + found = true; + break; + } } } + else { + found = true; + } - lua_pushboolean (L, true); - lua_pushinteger (L, i); + lua_pushboolean (L, found); } else { DL_FOREACH (rh, cur) { |