summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_http.c
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 /src/lua/lua_http.c
parent65adaacdc8a30aa1c163f5f120af0be16254544f (diff)
downloadrspamd-be8abd18254cb740d210d5ab6f697a2e2e941471.tar.gz
rspamd-be8abd18254cb740d210d5ab6f697a2e2e941471.zip
[Minor] Avoid one copy when publishing fuzzy updates
Diffstat (limited to 'src/lua/lua_http.c')
-rw-r--r--src/lua/lua_http.c31
1 files changed, 28 insertions, 3 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);