aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-30 13:27:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-30 14:16:43 +0000
commitbe8abd18254cb740d210d5ab6f697a2e2e941471 (patch)
tree7e368a1ed037d4b34693061b3935cdae60f5444c
parent65adaacdc8a30aa1c163f5f120af0be16254544f (diff)
downloadrspamd-be8abd18254cb740d210d5ab6f697a2e2e941471.tar.gz
rspamd-be8abd18254cb740d210d5ab6f697a2e2e941471.zip
[Minor] Avoid one copy when publishing fuzzy updates
-rw-r--r--src/lua/lua_http.c31
-rw-r--r--src/plugins/lua/fuzzy_collect.lua4
2 files changed, 31 insertions, 4 deletions
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 52509ab58..2213d8aae 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -55,6 +55,8 @@ static const struct luaL_reg httplib_m[] = {
{NULL, NULL}
};
+#define RSPAMD_LUA_HTTP_FLAG_TEXT (1 << 0)
+
struct lua_http_cbdata {
lua_State *L;
struct rspamd_http_connection *conn;
@@ -69,6 +71,7 @@ struct lua_http_cbdata {
rspamd_inet_addr_t *addr;
gchar *mime_type;
gchar *host;
+ gint flags;
gint fd;
gint cbref;
};
@@ -179,11 +182,22 @@ lua_http_finish_handler (struct rspamd_http_connection *conn,
/* Body */
body = rspamd_http_message_get_body (msg, &body_len);
- if (body_len > 0) {
- lua_pushlstring (cbd->L, body, body_len);
+ if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_TEXT) {
+ struct rspamd_lua_text *t;
+
+ t = lua_newuserdata (cbd->L, sizeof (*t));
+ rspamd_lua_setclass (cbd->L, "rspamd{text}", -1);
+ t->start = body;
+ t->len = body_len;
+ t->flags = 0;
}
else {
- lua_pushnil (cbd->L);
+ if (body_len > 0) {
+ lua_pushlstring (cbd->L, body, body_len);
+ }
+ else {
+ lua_pushnil (cbd->L);
+ }
}
/* Headers */
lua_newtable (cbd->L);
@@ -338,6 +352,7 @@ lua_http_request (lua_State *L)
struct rspamd_cryptobox_pubkey *peer_key = NULL;
struct rspamd_cryptobox_keypair *local_kp = NULL;
gdouble timeout = default_http_timeout;
+ gint flags = 0;
gchar *mime_type = NULL;
if (lua_gettop (L) >= 2) {
@@ -524,6 +539,15 @@ lua_http_request (lua_State *L)
}
lua_pop (L, 1);
+
+ lua_pushstring (L, "opaque_body");
+ lua_gettable (L, 1);
+
+ if (!!lua_toboolean (L, -1)) {
+ flags |= RSPAMD_LUA_HTTP_FLAG_TEXT;
+ }
+
+ lua_pop (L, 1);
}
else {
msg_err ("http request has bad params");
@@ -543,6 +567,7 @@ lua_http_request (lua_State *L)
cbd->cfg = cfg;
cbd->peer_pk = peer_key;
cbd->local_kp = local_kp;
+ cbd->flags = flags;
if (msg->host) {
cbd->host = rspamd_fstring_cstr (msg->host);
diff --git a/src/plugins/lua/fuzzy_collect.lua b/src/plugins/lua/fuzzy_collect.lua
index d421ef389..663f48e13 100644
--- a/src/plugins/lua/fuzzy_collect.lua
+++ b/src/plugins/lua/fuzzy_collect.lua
@@ -53,6 +53,7 @@ local function collect_fuzzy_hashes(cfg, ev_base)
if not body or err then
rspamd_logger.errx(cfg, 'cannot load data: %s', err)
else
+ -- Here, we actually copy body once for each mirror
fun.each(function(_, v) send_data_mirror(v, cfg, ev_base, body) end,
settings.mirrors)
end
@@ -81,7 +82,8 @@ local function collect_fuzzy_hashes(cfg, ev_base)
peer_key = settings.collect_pubkey,
headers = {
Signature = sig:hex()
- }
+ },
+ opaque_body = true,
}
end
else