aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-01-31 22:23:08 +0600
committerGitHub <noreply@github.com>2024-01-31 22:23:08 +0600
commit9259503f04a54fdb87ce972b162ed9950a164649 (patch)
tree7236645df1f4d012799a38c1f30d5c7e31454683
parent66fde72a407311b6cb8ae3f5724573c514630b95 (diff)
parentc8dc2b00f9faa87fcdaee8794d7e4db4746d6116 (diff)
downloadrspamd-9259503f04a54fdb87ce972b162ed9950a164649.tar.gz
rspamd-9259503f04a54fdb87ce972b162ed9950a164649.zip
Merge pull request #4802 from rspamd/vstakhov-proxy-host-fixes
Deal with `Connection` and `Host` headers on proxying
-rw-r--r--src/rspamd_proxy.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index 838de060e..191433aa4 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1443,6 +1443,14 @@ proxy_open_mirror_connections(struct rspamd_proxy_session *session)
continue;
}
+ const char *up_name = rspamd_upstream_name(bk_conn->up);
+
+ if (up_name) {
+ rspamd_http_message_remove_header(msg, "Host");
+ rspamd_http_message_add_header(msg, "Host", up_name);
+ }
+ rspamd_http_message_add_header(msg, "Connection", "close");
+
if (msg->url->len == 0) {
msg->url = rspamd_fstring_append(msg->url, "/check", strlen("/check"));
}
@@ -1927,8 +1935,14 @@ proxy_send_master_message(struct rspamd_proxy_session *session)
if (backend == NULL) {
backend = session->ctx->default_upstream;
}
+
+ /* Remove the original Host header */
+ rspamd_http_message_remove_header(session->client_message, "Host");
}
+ /* Remove the original `Connection` header */
+ rspamd_http_message_remove_header(session->client_message, "Connection");
+
if (backend == NULL) {
/* No backend */
msg_err_session("cannot find upstream for %s", host ? hostbuf : "default");
@@ -2004,6 +2018,14 @@ proxy_send_master_message(struct rspamd_proxy_session *session)
goto err; /* No fallback here */
}
+ /* Add new Host header */
+ const char *up_name = rspamd_upstream_name(session->master_conn->up);
+
+ if (up_name) {
+ rspamd_http_message_add_header(msg, "Host", up_name);
+ }
+ rspamd_http_message_add_header(msg, "Connection", "close");
+
session->master_conn->backend_conn = rspamd_http_connection_new_client_socket(
session->ctx->http_ctx,
NULL,