commit caac14e: [Minor] Use unified method to obtain http host
Vsevolod Stakhov
vsevolod at highsecure.ru
Sat Dec 11 12:35:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-12-11 12:30:09 +0000
URL: https://github.com/rspamd/rspamd/commit/caac14e056da239aa86b626b1ca8786628558cf0 (HEAD -> master)
[Minor] Use unified method to obtain http host
---
src/libserver/http/http_message.c | 26 ++++++++++++++++++++++++++
src/libserver/http/http_message.h | 8 ++++++++
src/lua/lua_http.c | 13 ++++++++-----
3 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/src/libserver/http/http_message.c b/src/libserver/http/http_message.c
index 962699a9c..a313283f3 100644
--- a/src/libserver/http/http_message.c
+++ b/src/libserver/http/http_message.c
@@ -690,4 +690,30 @@ rspamd_http_message_remove_header (struct rspamd_http_message *msg,
}
return res;
+}
+
+const gchar*
+rspamd_http_message_get_http_host (struct rspamd_http_message *msg)
+{
+ if (msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER) {
+ rspamd_ftok_t srch;
+
+ RSPAMD_FTOK_ASSIGN(&srch, "Host");
+
+ khiter_t k = kh_get (rspamd_http_headers_hash, msg->headers, &srch);
+
+ if (k != kh_end (msg->headers)) {
+ return (kh_value (msg->headers, k)->value).begin;
+ }
+ else if (msg->host) {
+ return msg->host->str;
+ }
+ }
+ else {
+ if (msg->host) {
+ return msg->host->str;
+ }
+ }
+
+ return NULL;
}
\ No newline at end of file
diff --git a/src/libserver/http/http_message.h b/src/libserver/http/http_message.h
index e13c7427c..1750c1dd6 100644
--- a/src/libserver/http/http_message.h
+++ b/src/libserver/http/http_message.h
@@ -229,6 +229,14 @@ void rspamd_http_message_shmem_unref (struct rspamd_storage_shmem *p);
*/
guint rspamd_http_message_get_flags (struct rspamd_http_message *msg);
+/**
+ * Returns an HTTP hostname for a message, derived from a header if it has it
+ * or from a url if it doesn't
+ * @param msg
+ * @return
+ */
+const gchar* rspamd_http_message_get_http_host (struct rspamd_http_message *msg);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 85aa04e1f..e4a3bedb1 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -75,7 +75,7 @@ struct lua_http_cbdata {
struct rspamd_cryptobox_pubkey *peer_pk;
rspamd_inet_addr_t *addr;
gchar *mime_type;
- gchar *host;
+ const gchar *host;
gchar *auth;
const gchar *url;
gsize max_size;
@@ -1054,12 +1054,13 @@ lua_http_request (lua_State *L)
bool numeric_ip = false;
/* Check if we can skip resolving */
- if (msg->host) {
- cbd->host = msg->host->str;
+ cbd->host = rspamd_http_message_get_http_host (msg);
+ if (cbd->host) {
if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_KEEP_ALIVE) {
const rspamd_inet_addr_t *ka_addr = rspamd_http_context_has_keepalive(NULL,
- msg->host->str, msg->port, msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
+ rspamd_http_message_get_http_host (msg),
+ msg->port, msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
if (ka_addr) {
cbd->addr = rspamd_inet_address_copy(ka_addr);
@@ -1068,8 +1069,10 @@ lua_http_request (lua_State *L)
}
if (!cbd->addr) {
+ /* We use msg->host here, not cbd->host ! */
if (rspamd_parse_inet_address (&cbd->addr,
- msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
+ msg->host->str, msg->host->len,
+ RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
numeric_ip = true;
}
}
More information about the Commits
mailing list