static gboolean extended_urls = FALSE;
static gboolean mime_output = FALSE;
static gboolean empty_input = FALSE;
+static gboolean compressed = FALSE;
static gchar *key = NULL;
static GList *children;
"Allow empty input instead of reading from stdin", NULL },
{ "fuzzy-symbol", 'S', 0, G_OPTION_ARG_STRING, &fuzzy_symbol,
"Learn the specified fuzzy symbol", NULL },
+ { "compressed", 'z', 0, G_OPTION_ARG_NONE, &compressed,
+ "Enable zstd compression", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
if (cmd->need_input) {
rspamd_client_command (conn, cmd->path, attrs, in, rspamc_client_cb,
- cbdata, &err);
+ cbdata, compressed, &err);
}
else {
rspamd_client_command (conn,
NULL,
rspamc_client_cb,
cbdata,
+ compressed,
&err);
}
}
#include "libutil/http.h"
#include "libutil/http_private.h"
#include "unix-std.h"
+#include "contrib/zstd/zstd.h"
#ifdef HAVE_FETCH_H
#include <fetch.h>
gboolean
rspamd_client_command (struct rspamd_client_connection *conn,
- const gchar *command, GQueue *attrs,
- FILE *in, rspamd_client_callback cb,
- gpointer ud, GError **err)
+ const gchar *command, GQueue *attrs,
+ FILE *in, rspamd_client_callback cb,
+ gpointer ud, gboolean compressed, GError **err)
{
struct rspamd_client_request *req;
struct rspamd_http_client_header *nh;
return FALSE;
}
- body = rspamd_fstring_new_init (input->str, input->len);
+ if (!compressed) {
+ body = rspamd_fstring_new_init (input->str, input->len);
+ }
+ else {
+ body = rspamd_fstring_sized_new (ZSTD_compressBound (input->len));
+ body->len = ZSTD_compress (body->str, body->allocated, input->str,
+ input->len, 1);
+
+ if (ZSTD_isError (body->len)) {
+ g_set_error (err, RCLIENT_ERROR, ferror (
+ in), "compression error");
+ g_slice_free1 (sizeof (struct rspamd_client_request), req);
+ g_string_free (input, TRUE);
+ rspamd_fstring_free (body);
+
+ return FALSE;
+ }
+ }
+
rspamd_http_message_set_body_from_fstring_steal (req->msg, body);
req->input = input;
}
cur = g_list_next (cur);
}
+ if (compressed) {
+ rspamd_http_message_add_header (req->msg, "Compression", "zstd");
+ }
+
req->msg->url = rspamd_fstring_append (req->msg->url, "/", 1);
req->msg->url = rspamd_fstring_append (req->msg->url, command, strlen (command));
conn->req = req;
- rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL,
- "text/plain", req, conn->fd, &conn->timeout, conn->ev_base);
+ if (compressed) {
+ rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL,
+ "application/x-compressed", req, conn->fd,
+ &conn->timeout, conn->ev_base);
+ }
+ else {
+ rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL,
+ "text/plain", req, conn->fd, &conn->timeout, conn->ev_base);
+ }
return TRUE;
}