Browse Source

[Feature] Support User-Agent in HTTP requests

Issue: #2750
Closes: #2750
tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
cd2f92e40e
4 changed files with 26 additions and 5 deletions
  1. 0
    4
      src/client/rspamc.c
  2. 5
    0
      src/libutil/http_connection.c
  3. 14
    0
      src/libutil/http_context.c
  4. 7
    1
      src/plugins/dkim_check.c

+ 0
- 4
src/client/rspamc.c View 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;


+ 5
- 0
src/libutil/http_connection.c View 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);


+ 14
- 0
src/libutil/http_context.c View 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");

+ 7
- 1
src/plugins/dkim_check.c View 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) {

Loading…
Cancel
Save