[libsoup/soup-uri-removal: 2/2] server: Fix path decoding on SoupServer




commit 8b71d211a62ac3c34db0f53a266bc8445b39ce28
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Tue Oct 13 15:15:07 2020 +0200

    server: Fix path decoding on SoupServer
    
    SoupServer decodes the paths when raw-paths property is FALSE, but
    calling soup_message_set_uri() with the decoded uri, encodes it again
    because of the normalization. Since we know the uri is already
    normalized, we just want to change the path, so I've added a private
    function to set the uri of a SoupMessage without doing the
    normalization.
    
    Fixes server-auth-test

 libsoup/soup-message-private.h |  3 +++
 libsoup/soup-message.c         | 13 +++++++++++++
 libsoup/soup-server.c          |  8 +++++---
 3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 8fc64d79..bf1e1bbd 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -176,5 +176,8 @@ void                soup_message_set_bytes_for_sniffing (SoupMessage        *msg
 
 const char *soup_http_version_to_string      (SoupHTTPVersion version);
 
+void soup_message_set_uri_no_normalize (SoupMessage *msg,
+                                       GUri        *uri);
+
 
 #endif /* __SOUP_MESSAGE_PRIVATE_H__ */
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index ebe12d72..7531ff9a 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -1697,6 +1697,19 @@ soup_message_set_uri (SoupMessage *msg, GUri *uri)
        g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
 }
 
+void
+soup_message_set_uri_no_normalize (SoupMessage *msg,
+                                  GUri        *uri)
+{
+       SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+
+       if (priv->uri)
+                g_uri_unref (priv->uri);
+        priv->uri = g_uri_ref (uri);
+
+       g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
+}
+
 /**
  * soup_message_get_uri:
  * @msg: a #SoupMessage
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index a3ce755b..90881b62 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -965,7 +965,7 @@ static GUri *
 uri_set_path (GUri *uri, const char *path)
 {
         return g_uri_build_with_user (
-                g_uri_get_flags (uri) ^ G_URI_FLAGS_ENCODED_PATH,
+                g_uri_get_flags (uri),
                 g_uri_get_scheme (uri),
                 g_uri_get_user (uri),
                 g_uri_get_password (uri),
@@ -1012,6 +1012,7 @@ got_headers (SoupMessage *msg, SoupClientContext *client)
 
        if (!priv->raw_paths && g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_PATH) {
                char *decoded_path;
+               GUri *decoded_uri;
 
                 decoded_path = g_uri_unescape_string (g_uri_get_path (uri), NULL);
 
@@ -1031,9 +1032,10 @@ got_headers (SoupMessage *msg, SoupClientContext *client)
                        return;
                }
 
-                uri = uri_set_path (uri, decoded_path);
-                soup_message_set_uri (msg, uri);
+                decoded_uri = uri_set_path (uri, decoded_path);
+                soup_message_set_uri_no_normalize (msg, decoded_uri);
                g_free (decoded_path);
+               g_uri_unref (decoded_uri);
        }
 
        /* Now handle authentication. (We do this here so that if


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