[libsoup] Revert "Set the Host header before emiting SoupMessage::starting"



commit 3579711dbccf00a0b8233abd0c0b717edb756ad1
Author: Patrick Griffis <pgriffis igalia com>
Date:   Fri Dec 4 11:00:47 2020 -0600

    Revert "Set the Host header before emiting SoupMessage::starting"
    
    This reverts commit 53c357cea3b65f0660ec6b589f73bf32bd090229.
    
    This fixes redirection for now.

 libsoup/soup-logger.c            | 22 +++++++++++++++++++++-
 libsoup/soup-message-io.c        | 22 +++++++++++++++++++---
 libsoup/soup-session.c           | 21 ++-------------------
 libsoup/soup-uri-utils-private.h |  2 --
 libsoup/soup-uri-utils.c         | 13 -------------
 5 files changed, 42 insertions(+), 38 deletions(-)
---
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index f82d73e4..e4f9c276 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -18,6 +18,7 @@
 #include "soup-connection.h"
 #include "soup-message-private.h"
 #include "soup-misc.h"
+#include "soup-uri-utils-private.h"
 #include "soup.h"
 #include "soup-session-feature-private.h"
 
@@ -514,6 +515,22 @@ print_request (SoupLogger *logger, SoupMessage *msg,
        if (log_level == SOUP_LOGGER_LOG_MINIMAL)
                return;
 
+       if (!soup_message_headers_get_one (soup_message_get_request_headers (msg), "Host")) {
+               char *uri_host = (char*)g_uri_get_host (uri);
+
+               if (strchr (uri_host, ':'))
+                       uri_host = g_strdup_printf ("[%s]", uri_host);
+               else if (g_hostname_is_non_ascii (uri_host))
+                       uri_host = g_hostname_to_ascii (uri_host);
+
+               soup_logger_print (logger, SOUP_LOGGER_LOG_HEADERS, '>',
+                                  "Host: %s%c%u", uri_host,
+                                  soup_uri_uses_default_port (uri) ? '\0' : ':',
+                                  g_uri_get_port (uri));
+
+               if (uri_host != g_uri_get_host (uri))
+                       g_free (uri_host);
+       }
        soup_message_headers_iter_init (&iter, soup_message_get_request_headers (msg));
        while (soup_message_headers_iter_next (&iter, &name, &value)) {
                if (!g_ascii_strcasecmp (name, "Authorization") &&
@@ -672,7 +689,10 @@ soup_logger_request_unqueued (SoupSessionFeature *logger,
 {
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
-       g_signal_handlers_disconnect_by_data (msg, logger);
+       g_signal_handlers_disconnect_by_func (msg, starting, logger);
+       g_signal_handlers_disconnect_by_func (msg, got_informational, logger);
+       g_signal_handlers_disconnect_by_func (msg, got_body, logger);
+       g_signal_handlers_disconnect_by_func (msg, finished, logger);
 }
 
 static void
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index 064f3d35..1055c099 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -259,16 +259,20 @@ write_headers (SoupMessage          *msg,
               SoupEncoding         *encoding)
 {
        GUri *uri = soup_message_get_uri (msg);
+       char *uri_host;
        char *uri_string;
        SoupMessageHeadersIter iter;
        const char *name, *value;
 
-       if (soup_message_get_method (msg) == SOUP_METHOD_CONNECT) {
-               char *uri_host = soup_uri_get_host_for_headers (uri);
+        uri_host = (char*)g_uri_get_host (uri);
+       if (strchr (uri_host, ':'))
+               uri_host = g_strdup_printf ("[%.*s]", (int) strcspn (uri_host, "%"), uri_host);
+       else if (g_hostname_is_non_ascii (uri_host))
+               uri_host = g_hostname_to_ascii (uri_host);
 
+       if (soup_message_get_method (msg) == SOUP_METHOD_CONNECT) {
                /* CONNECT URI is hostname:port for tunnel destination */
                uri_string = g_strdup_printf ("%s:%d", uri_host, g_uri_get_port (uri));
-               g_free (uri_host);
        } else {
                gboolean proxy = soup_connection_is_via_proxy (conn);
 
@@ -293,7 +297,19 @@ write_headers (SoupMessage          *msg,
        g_string_append_printf (header, "%s %s HTTP/1.%d\r\n",
                                soup_message_get_method (msg), uri_string,
                                (soup_message_get_http_version (msg) == SOUP_HTTP_1_0) ? 0 : 1);
+
+       if (!soup_message_headers_get_one (soup_message_get_request_headers (msg), "Host")) {
+               if (soup_uri_uses_default_port (uri)) {
+                       g_string_append_printf (header, "Host: %s\r\n",
+                                               uri_host);
+               } else {
+                       g_string_append_printf (header, "Host: %s:%d\r\n",
+                                               uri_host, g_uri_get_port (uri));
+               }
+       }
        g_free (uri_string);
+       if (uri_host != g_uri_get_host (uri))
+               g_free (uri_host);
 
        *encoding = soup_message_headers_get_encoding (soup_message_get_request_headers (msg));
 
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index c78df326..256bb63f 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -993,9 +993,9 @@ soup_session_send_queue_item (SoupSession *session,
                              SoupMessageIOCompletionFn completion_cb)
 {
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
-       SoupMessageHeaders *request_headers;
+        SoupMessageHeaders *request_headers;
 
-       request_headers = soup_message_get_request_headers (item->msg);
+        request_headers = soup_message_get_request_headers (item->msg);
        if (priv->user_agent)
                soup_message_headers_replace (request_headers, "User-Agent", priv->user_agent);
 
@@ -1013,23 +1013,6 @@ soup_session_send_queue_item (SoupSession *session,
                soup_message_headers_append (request_headers, "Connection", "Keep-Alive");
        }
 
-        if (!soup_message_headers_get_one (request_headers, "Host")) {
-                GUri *uri = soup_message_get_uri (item->msg);
-                char *host;
-
-                host = soup_uri_get_host_for_headers (uri);
-                if (soup_uri_uses_default_port (uri))
-                        soup_message_headers_append (request_headers, "Host", host);
-                else {
-                        char *value;
-
-                        value = g_strdup_printf ("%s:%d", host, g_uri_get_port (uri));
-                        soup_message_headers_append (request_headers, "Host", value);
-                        g_free (value);
-                }
-                g_free (host);
-        }
-
        soup_message_starting (item->msg);
        if (item->state == SOUP_MESSAGE_RUNNING)
                soup_connection_send_request (item->conn, item, completion_cb, item);
diff --git a/libsoup/soup-uri-utils-private.h b/libsoup/soup-uri-utils-private.h
index 6bc2b38d..b741a6d7 100644
--- a/libsoup/soup-uri-utils-private.h
+++ b/libsoup/soup-uri-utils-private.h
@@ -28,8 +28,6 @@ gboolean     soup_uri_host_equal            (gconstpointer v1, gconstpointer v2)
 
 GUri        *soup_uri_copy_with_normalized_flags (GUri  *uri);
 
-char        *soup_uri_get_host_for_headers  (GUri       *uri);
-
 #define SOUP_URI_IS_VALID(x) (x && g_uri_get_host(x) && g_uri_get_host(x)[0])
 
 G_END_DECLS
diff --git a/libsoup/soup-uri-utils.c b/libsoup/soup-uri-utils.c
index de4a162a..4bc4c11c 100644
--- a/libsoup/soup-uri-utils.c
+++ b/libsoup/soup-uri-utils.c
@@ -489,16 +489,3 @@ soup_uri_copy_with_normalized_flags (GUri *uri)
                 g_uri_get_fragment (uri)
         );
 }
-
-char *
-soup_uri_get_host_for_headers (GUri *uri)
-{
-        const char *host = g_uri_get_host (uri);
-
-        if (strchr (host, ':'))
-                return g_strdup_printf ("[%.*s]", (int)strcspn (host, "%"), host);
-        if (g_hostname_is_non_ascii (host))
-                return g_hostname_to_ascii (host);
-
-        return g_strdup (host);
-}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]