{NULL, NULL}
};
+#define RSPAMD_LUA_HTTP_FLAG_TEXT (1 << 0)
+
struct lua_http_cbdata {
lua_State *L;
struct rspamd_http_connection *conn;
rspamd_inet_addr_t *addr;
gchar *mime_type;
gchar *host;
+ gint flags;
gint fd;
gint cbref;
};
/* 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);
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) {
}
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");
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);
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
peer_key = settings.collect_pubkey,
headers = {
Signature = sig:hex()
- }
+ },
+ opaque_body = true,
}
end
else