* @return {table rspamd_mime_part} list of mime parts
*/
LUA_FUNCTION_DEF (task, get_parts);
+
+/***
+ * @method task:get_request_header(name)
+ * Get value of a HTTP request header.
+ * @param {string} name name of header to get
+ * @return {rspamd_text} value of an HTTP header
+ */
+LUA_FUNCTION_DEF (task, get_request_header);
+/***
+ * @method task:set_request_header(name, value)
+ * Set value of a HTTP request header. If value is omitted, then a header is removed
+ * @param {string} name name of header to get
+ * @param {rspamd_text/string} value new header's value
+ */
+LUA_FUNCTION_DEF (task, set_request_header);
/***
* @method task:get_header(name[, case_sensitive])
* Get decoded value of a header specified with optional case_sensitive flag.
LUA_INTERFACE_DEF (task, get_emails),
LUA_INTERFACE_DEF (task, get_text_parts),
LUA_INTERFACE_DEF (task, get_parts),
+ LUA_INTERFACE_DEF (task, get_request_header),
+ LUA_INTERFACE_DEF (task, set_request_header),
LUA_INTERFACE_DEF (task, get_header),
LUA_INTERFACE_DEF (task, get_header_raw),
LUA_INTERFACE_DEF (task, get_header_full),
return 1;
}
+static gint
+lua_task_get_request_header (lua_State *L)
+{
+ GString *hdr, srch;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *s;
+ struct rspamd_lua_text *t;
+ gsize len;
+
+ s = luaL_checklstring (L, 2, &len);
+
+ if (s) {
+ srch.str = (gchar *)s;
+ srch.len = len;
+
+ hdr = g_hash_table_lookup (task->request_headers, &srch);
+
+ if (hdr) {
+ t = lua_newuserdata (L, sizeof (*t));
+ rspamd_lua_setclass (L, "rspamd{text}", -1);
+ t->start = hdr->str;
+ t->len = hdr->len;
+ t->own = FALSE;
+
+ return 1;
+ }
+ }
+
+ lua_pushnil (L);
+ return 1;
+}
+
+static gint
+lua_task_set_request_header (lua_State *L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ const gchar *s, *v = NULL;
+ struct rspamd_lua_text *t;
+ GString *hdr, srch, *new_name;
+ gsize len, vlen;
+
+ s = luaL_checklstring (L, 2, &len);
+
+ if (s) {
+ if (lua_type (L, 3) == LUA_TSTRING) {
+ v = luaL_checklstring (L, 2, &vlen);
+ }
+ else if (lua_type (L, 3) == LUA_TUSERDATA) {
+ t = lua_check_text (L, 3);
+
+ if (t != NULL) {
+ v = t->start;
+ vlen = t->len;
+ }
+ }
+
+ if (v != NULL) {
+ srch.str = (gchar *)s;
+ srch.len = len;
+
+ hdr = g_hash_table_lookup (task->request_headers, &srch);
+
+ if (hdr) {
+ new_name = &srch;
+ }
+ else {
+ /* Not found, need to allocate */
+ new_name = g_string_new_len (srch.str, srch.len);
+ }
+ hdr = g_string_new_len (v, vlen);
+
+ /* This does not destroy key if it exists */
+ g_hash_table_insert (task->request_headers, new_name, hdr);
+ }
+
+ }
+
+ return 0;
+}
gint
rspamd_lua_push_header (lua_State * L,