]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Make server header reply configurable
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Feb 2020 17:49:03 +0000 (17:49 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Feb 2020 17:49:03 +0000 (17:49 +0000)
src/libutil/http_connection.c
src/libutil/http_context.c
src/libutil/http_context.h

index 3848788d62954ac633951f80a5d5fefde916b50e..027dc9d5b9af22991cd5c0e13b4ed986b170991d 100644 (file)
@@ -1713,7 +1713,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                                        "Date: %s\r\n"
                                                                                        "Content-Length: %z\r\n"
                                                                                        "Content-Type: %s", /* NO \r\n at the end ! */
-                                                                       msg->code, &status, "rspamd/" RVERSION,
+                                                                       msg->code, &status, priv->ctx->config.server_hdr,
                                                                        datebuf,
                                                                        bodylen, mime_type);
                                }
@@ -1725,7 +1725,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                                        "Server: %s\r\n"
                                                                                        "Date: %s\r\n"
                                                                                        "Content-Length: %z", /* NO \r\n at the end ! */
-                                                                       msg->code, &status, "rspamd/" RVERSION,
+                                                                       msg->code, &status, priv->ctx->config.server_hdr,
                                                                        datebuf,
                                                                        bodylen);
                                }
@@ -1734,10 +1734,11 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                rspamd_printf_fstring (buf,
                                                "HTTP/1.1 200 OK\r\n"
                                                "Connection: close\r\n"
-                                               "Server: rspamd\r\n"
+                                               "Server: %s\r\n"
                                                "Date: %s\r\n"
                                                "Content-Length: %z\r\n"
                                                "Content-Type: application/octet-stream\r\n",
+                                               priv->ctx->config.server_hdr,
                                                datebuf, enclen);
                        }
                        else {
@@ -1750,7 +1751,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                                        "Date: %s\r\n"
                                                                                        "Content-Length: %z\r\n"
                                                                                        "Content-Type: %s\r\n",
-                                                                       msg->code, &status, "rspamd/" RVERSION,
+                                                                       msg->code, &status, priv->ctx->config.server_hdr,
                                                                        datebuf,
                                                                        bodylen, mime_type);
                                }
@@ -1762,7 +1763,7 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                                        "Server: %s\r\n"
                                                                                        "Date: %s\r\n"
                                                                                        "Content-Length: %z\r\n",
-                                                                       msg->code, &status, "rspamd/" RVERSION,
+                                                                       msg->code, &status, priv->ctx->config.server_hdr,
                                                                        datebuf,
                                                                        bodylen);
                                }
index 4d701d0c5190256bd1de1fe7f9d6594082fec17f..d7e530d56239463253e16253ff1ef00e0e160ca9 100644 (file)
@@ -92,6 +92,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
        static const gdouble default_rotate_time = 120;
        static const gdouble default_keepalive_interval = 65;
        static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
+       static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL;
 
        ctx = g_malloc0 (sizeof (*ctx));
        ctx->config.kp_cache_size_client = default_kp_size;
@@ -99,6 +100,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
        ctx->config.client_key_rotate_time = default_rotate_time;
        ctx->config.user_agent = default_user_agent;
        ctx->config.keepalive_interval = default_keepalive_interval;
+       ctx->config.server_hdr = default_server_hdr;
        ctx->ups_ctx = ups_ctx;
 
        if (cfg) {
@@ -243,6 +245,17 @@ rspamd_http_context_create (struct rspamd_config *cfg,
                                }
                        }
 
+                       const ucl_object_t *server_hdr;
+                       server_hdr = ucl_object_lookup (client_obj, "server_hdr");
+
+                       if (server_hdr) {
+                               ctx->config.server_hdr = ucl_object_tostring (server_hdr);
+
+                               if (ctx->config.server_hdr && strlen (ctx->config.server_hdr) == 0) {
+                                       ctx->config.server_hdr = "";
+                               }
+                       }
+
                        const ucl_object_t *keepalive_interval;
 
                        keepalive_interval = ucl_object_lookup (client_obj, "keepalive_interval");
index f7697c4067fe9899ce4fc8bfb730d9d758e2a9fa..82ee400b0ee4a3887718f077de18646cb3763102 100644 (file)
@@ -40,6 +40,7 @@ struct rspamd_http_context_cfg {
        gdouble client_key_rotate_time;
        const gchar *user_agent;
        const gchar *http_proxy;
+       const gchar *server_hdr;
 };
 
 /**
@@ -49,7 +50,8 @@ struct rspamd_http_context_cfg {
  * @return new context used for both client and server HTTP connections
  */
 struct rspamd_http_context *rspamd_http_context_create (struct rspamd_config *cfg,
-                                                                                                               struct ev_loop *ev_base, struct upstream_ctx *ctx);
+                                                                                                               struct ev_loop *ev_base,
+                                                                                                               struct upstream_ctx *ctx);
 
 struct rspamd_http_context *rspamd_http_context_create_config (
                struct rspamd_http_context_cfg *cfg,