]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support User-Agent in HTTP requests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Feb 2019 13:05:56 +0000 (13:05 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Feb 2019 13:05:56 +0000 (13:05 +0000)
Issue: #2750
Closes: #2750
src/client/rspamc.c
src/libutil/http_connection.c
src/libutil/http_context.c
src/plugins/dkim_check.c

index d9af90b7fdba634297ba7b2eee2ce492a9bd052f..0568692b4906b168e57ba7221a724d5173a9f04c 100644 (file)
@@ -554,10 +554,6 @@ add_options (GQueue *opts)
        GString *numbuf;
        gchar **hdr, **rcpt;
 
-       if (user_agent) {
-               ADD_CLIENT_HEADER (opts, "User-Agent", user_agent);
-       }
-
        if (ip != NULL) {
                rspamd_inet_addr_t *addr = NULL;
 
index 8463ff76249831f32733b05382dc9283a28e0c12..fd052951b9874e4e6aebaea65ffa3a0345cb26d0 100644 (file)
@@ -1805,6 +1805,11 @@ rspamd_http_connection_write_message_common (struct rspamd_http_connection *conn
                }
        }
 
+       if (priv->ctx->config.user_agent) {
+               rspamd_http_message_add_header (msg, "User-Agent",
+                               priv->ctx->config.user_agent);
+       }
+
        if (encrypted) {
                mode = rspamd_keypair_alg (priv->local_key);
 
index 0237af1abcb22c83a337aed5225629c3a3c71f14..39a02b179d30fb29f3bb2f37e21318447ac4bd20 100644 (file)
@@ -50,11 +50,13 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 
        static const int default_kp_size = 1024;
        static const gdouble default_rotate_time = 120;
+       static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
 
        ctx = g_malloc0 (sizeof (*ctx));
        ctx->config.kp_cache_size_client = default_kp_size;
        ctx->config.kp_cache_size_server = default_kp_size;
        ctx->config.client_key_rotate_time = default_rotate_time;
+       ctx->config.user_agent = default_user_agent;
 
        if (cfg) {
                ctx->ssl_ctx = cfg->libs_ctx->ssl_ctx;
@@ -127,6 +129,18 @@ rspamd_http_context_create (struct rspamd_config *cfg,
                        if (rotate_time) {
                                ctx->config.client_key_rotate_time = ucl_object_todouble (rotate_time);
                        }
+
+                       const ucl_object_t *user_agent;
+
+                       user_agent = ucl_object_lookup (client_obj, "user_agent");
+
+                       if (user_agent) {
+                               ctx->config.user_agent = ucl_object_tostring (user_agent);
+
+                               if (ctx->config.user_agent && strlen (ctx->config.user_agent) == 0) {
+                                       ctx->config.user_agent = NULL;
+                               }
+                       }
                }
 
                server_obj = ucl_object_lookup (http_obj, "server");
index b7e9e53eee0d403e4b0e27544f24b977b280f136..f7600552b965607c3dea6181fc2a189b8bc8d746 100644 (file)
@@ -1545,7 +1545,13 @@ dkim_module_lua_push_verify_result (struct rspamd_dkim_lua_verify_cbdata *cbd,
        ptask = lua_newuserdata (cbd->L, sizeof (*ptask));
        *ptask = task;
        lua_pushboolean (cbd->L, success);
-       lua_pushstring (cbd->L, error_str);
+
+       if (error_str) {
+               lua_pushstring (cbd->L, error_str);
+       }
+       else {
+               lua_pushnil (cbd->L);
+       }
 
        if (cbd->ctx) {
                if (res->domain) {