diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-19 17:16:21 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-19 17:16:21 +0100 |
commit | 0d993808484537046f93dd938a07e2e2c2e9ac87 (patch) | |
tree | 1fe810293d4188b17cdd2eb7637b848a996f471c | |
parent | e1c695b059428b6daa385ced5bfda2c9cdf98a75 (diff) | |
download | rspamd-0d993808484537046f93dd938a07e2e2c2e9ac87.tar.gz rspamd-0d993808484537046f93dd938a07e2e2c2e9ac87.zip |
Add ability to specify custom headers for rspamc client
-rw-r--r-- | doc/rspamc.1.md | 3 | ||||
-rw-r--r-- | src/client/rspamc.c | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/doc/rspamc.1.md b/doc/rspamc.1.md index f4d089bc1..99bfea376 100644 --- a/doc/rspamc.1.md +++ b/doc/rspamc.1.md @@ -111,6 +111,9 @@ requires input. \--mime : Output the full mime message instead of scanning results only +\--header=*header* +: Add custom HTTP header for a request. You may specify header in format `name=value` or just `name` for an empty header. This option can be repeated multiple times. + \--commands : List available commands diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 9be97cba0..7c0e76d5c 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -48,6 +48,7 @@ static gchar *hostname = "localhost"; static gchar *classifier = "bayes"; static gchar *local_addr = NULL; static gchar *execute = NULL; +static gchar **http_headers = NULL; static gint weight = 0; static gint flag = 0; static gint max_requests = 8; @@ -118,6 +119,8 @@ static GOptionEntry entries[] = "Execute the specified command and pass output to it", NULL }, { "mime", 'e', 0, G_OPTION_ARG_NONE, &mime_output, "Write mime body of message with headers instead of just a scan's result", NULL }, + {"header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &http_headers, + "Add custom HTTP header to query (can be repeated)", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; @@ -389,6 +392,7 @@ static void add_options (GHashTable *opts) { GString *numbuf; + gchar **hdr; if (ip != NULL) { g_hash_table_insert (opts, "Ip", ip); @@ -430,6 +434,25 @@ add_options (GHashTable *opts) if (extended_urls) { g_hash_table_insert (opts, "URL-Format", "extended"); } + + hdr = http_headers; + + while (*hdr != NULL) { + gchar **kv = g_strsplit_set (*hdr, ":=", 2); + + if (kv == NULL || kv[1] == NULL) { + g_hash_table_insert (opts, *hdr, ""); + + if (kv) { + g_strfreev (kv); + } + } + else { + g_hash_table_insert (opts, kv[0], kv[1]); + } + + hdr ++; + } } static void |