]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Use unified method to obtain http host
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 11 Dec 2021 12:30:09 +0000 (12:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 11 Dec 2021 12:31:05 +0000 (12:31 +0000)
src/libserver/http/http_message.c
src/libserver/http/http_message.h
src/lua/lua_http.c

index 962699a9c7844cec7acf9ce1953013665a11354c..a313283f36f6ef68090671929492276cda9f3abf 100644 (file)
@@ -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
index e13c7427c134dc426ba2c96f71ead82f7f918d2f..1750c1dd6fb6a471376c75dd00f870ce8435d63f 100644 (file)
@@ -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
index 85aa04e1f3c715b2847e6848139db4129e066e1d..e4a3bedb18b7c3cdb2fcdf946752858bdbaf2e3d 100644 (file)
@@ -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;
                        }
                }