diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-12-11 12:30:09 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-12-11 12:31:05 +0000 |
commit | caac14e056da239aa86b626b1ca8786628558cf0 (patch) | |
tree | ded6c8163aaedb5515c7fa1daba2290b18c87264 /src/libserver/http | |
parent | 0d4c611c689bfc434132458239a7395b5204c833 (diff) | |
download | rspamd-caac14e056da239aa86b626b1ca8786628558cf0.tar.gz rspamd-caac14e056da239aa86b626b1ca8786628558cf0.zip |
[Minor] Use unified method to obtain http host
Diffstat (limited to 'src/libserver/http')
-rw-r--r-- | src/libserver/http/http_message.c | 26 | ||||
-rw-r--r-- | src/libserver/http/http_message.h | 8 |
2 files changed, 34 insertions, 0 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 |