Browse Source

Merge pull request #4802 from rspamd/vstakhov-proxy-host-fixes

Deal with `Connection` and `Host` headers on proxying
tags/3.8.2
Vsevolod Stakhov 4 months ago
parent
commit
9259503f04
No account linked to committer's email address
1 changed files with 23 additions and 1 deletions
  1. 23
    1
      src/rspamd_proxy.c

+ 23
- 1
src/rspamd_proxy.c View File

/* /*
* Copyright 2023 Vsevolod Stakhov
* Copyright 2024 Vsevolod Stakhov
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
continue; 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) { if (msg->url->len == 0) {
msg->url = rspamd_fstring_append(msg->url, "/check", strlen("/check")); msg->url = rspamd_fstring_append(msg->url, "/check", strlen("/check"));
} }
if (backend == NULL) { if (backend == NULL) {
backend = session->ctx->default_upstream; 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) { if (backend == NULL) {
/* No backend */ /* No backend */
msg_err_session("cannot find upstream for %s", host ? hostbuf : "default"); msg_err_session("cannot find upstream for %s", host ? hostbuf : "default");
goto err; /* No fallback here */ 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->master_conn->backend_conn = rspamd_http_connection_new_client_socket(
session->ctx->http_ctx, session->ctx->http_ctx,
NULL, NULL,

Loading…
Cancel
Save