]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add port to the `Host` header if using non-standard ports
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 19 Nov 2022 14:24:41 +0000 (14:24 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 19 Nov 2022 14:24:41 +0000 (14:24 +0000)
src/libserver/http/http_connection.c
src/libserver/http/http_message.c
src/libserver/http/http_message.h

index a0cbf0dcedd4b480daea066bfe7c004d4ad7b0a3..e1c6ccf316d63c872306d37617fc3a2ab3dff2f7 100644 (file)
@@ -1867,7 +1867,8 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
 
                        if (encrypted) {
                                /* TODO: Add proxy support to HTTPCrypt */
-                               rspamd_printf_fstring (buf,
+                               if (rspamd_http_message_is_standard_port(msg)) {
+                                       rspamd_printf_fstring(buf,
                                                "%s %s HTTP/1.1\r\n"
                                                "Connection: %s\r\n"
                                                "Host: %s\r\n"
@@ -1878,9 +1879,25 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                conn_type,
                                                host,
                                                enclen);
+                               }
+                               else {
+                                       rspamd_printf_fstring(buf,
+                                               "%s %s HTTP/1.1\r\n"
+                                               "Connection: %s\r\n"
+                                               "Host: %s:%d\r\n"
+                                               "Content-Length: %z\r\n"
+                                               "Content-Type: application/octet-stream\r\n",
+                                               "POST",
+                                               "/post",
+                                               conn_type,
+                                               host,
+                                               msg->port,
+                                               enclen);
+                               }
                        }
                        else {
                                if (conn->priv->flags & RSPAMD_HTTP_CONN_FLAG_PROXY) {
+                                       /* Write proxied request */
                                        if ((msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER)) {
                                                rspamd_printf_fstring(buf,
                                                                "%s %s://%s:%d/%V HTTP/1.1\r\n"
@@ -1895,7 +1912,8 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                bodylen);
                                        }
                                        else {
-                                               rspamd_printf_fstring(buf,
+                                               if (rspamd_http_message_is_standard_port(msg)) {
+                                                       rspamd_printf_fstring(buf,
                                                                "%s %s://%s:%d/%V HTTP/1.1\r\n"
                                                                "Connection: %s\r\n"
                                                                "Host: %s\r\n"
@@ -1908,9 +1926,27 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                conn_type,
                                                                host,
                                                                bodylen);
+                                               }
+                                               else {
+                                                       rspamd_printf_fstring(buf,
+                                                               "%s %s://%s:%d/%V HTTP/1.1\r\n"
+                                                               "Connection: %s\r\n"
+                                                               "Host: %s:%d\r\n"
+                                                               "Content-Length: %z\r\n",
+                                                               http_method_str(msg->method),
+                                                               (conn->opts & RSPAMD_HTTP_CLIENT_SSL) ? "https" : "http",
+                                                               host,
+                                                               msg->port,
+                                                               msg->url,
+                                                               conn_type,
+                                                               host,
+                                                               msg->port,
+                                                               bodylen);
+                                               }
                                        }
                                }
                                else {
+                                       /* Unproxied version */
                                        if ((msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER)) {
                                                rspamd_printf_fstring(buf,
                                                                "%s %V HTTP/1.1\r\n"
@@ -1922,7 +1958,8 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                bodylen);
                                        }
                                        else {
-                                               rspamd_printf_fstring(buf,
+                                               if (rspamd_http_message_is_standard_port(msg)) {
+                                                       rspamd_printf_fstring(buf,
                                                                "%s %V HTTP/1.1\r\n"
                                                                "Connection: %s\r\n"
                                                                "Host: %s\r\n"
@@ -1932,6 +1969,20 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
                                                                conn_type,
                                                                host,
                                                                bodylen);
+                                               }
+                                               else {
+                                                       rspamd_printf_fstring(buf,
+                                                               "%s %V HTTP/1.1\r\n"
+                                                               "Connection: %s\r\n"
+                                                               "Host: %s:%d\r\n"
+                                                               "Content-Length: %z\r\n",
+                                                               http_method_str(msg->method),
+                                                               msg->url,
+                                                               conn_type,
+                                                               host,
+                                                               msg->port,
+                                                               bodylen);
+                                               }
                                        }
                                }
 
index 23ff85cd74c83fc0cfb02e01e4729a186afd3ead..435cdcf1344cce7c74d2b9be8278ad49f37d0540 100644 (file)
@@ -720,4 +720,14 @@ rspamd_http_message_get_http_host (struct rspamd_http_message *msg,
        }
 
        return NULL;
+}
+
+bool
+rspamd_http_message_is_standard_port(struct rspamd_http_message *msg)
+{
+       if (msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL) {
+               return msg->port == 443;
+       }
+
+       return msg->port == 80;
 }
\ No newline at end of file
index 38f59904863e97be8ec2e70f770cdebbfefa5d7c..f0c0cc2dc5cd65f7aebc71dd23b62f29eb0290b4 100644 (file)
@@ -239,6 +239,13 @@ guint rspamd_http_message_get_flags (struct rspamd_http_message *msg);
 const gchar* rspamd_http_message_get_http_host (struct rspamd_http_message *msg,
                gsize *hostlen);
 
+/**
+ * Returns true if a message has standard port (80 or 443 for https)
+ * @param msg
+ * @return
+ */
+bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg);
+
 #ifdef  __cplusplus
 }
 #endif