[libsoup] SoupSession: give password to GSimpleProxyResolver



commit a4b3f0a3c76d5bd65876d1bb134ac34416bec493
Author: Jonathan Lebon <jlebon redhat com>
Date:   Fri Oct 14 09:17:42 2016 -0400

    SoupSession: give password to GSimpleProxyResolver
    
    After setting the "proxy-uri" property on a SoupSession with embedded
    basic auth (e.g. http://user:pass example com), libsoup does not make
    use of the auth and ends up emitting an "authenticate" signal on
    receiving 407. Calling soup_auth_anthenticate() with the same
    credentials then works, but it should've made use of the auth from the
    beginning to avoid the round trip.
    
    This seems to be a regression from fb09bf93
    (https://bugzilla.gnome.org/show_bug.cgi?id=680273), during the
    transition to GSimpleProxyResolver. The issue is that libsoup uses
    `soup_uri_to_string_internal`, which doesn't embed the password in the
    resulting string.
    
    The attached patch changes this, making sure to retain the previous
    behaviour in all other cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772932

 libsoup/soup-address.c      |    2 +-
 libsoup/soup-misc-private.h |    2 +-
 libsoup/soup-session.c      |    2 +-
 libsoup/soup-uri.c          |    8 ++++++--
 4 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/libsoup/soup-address.c b/libsoup/soup-address.c
index 59598b2..6daf668 100644
--- a/libsoup/soup-address.c
+++ b/libsoup/soup-address.c
@@ -1267,7 +1267,7 @@ soup_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
        soup_uri_set_host (uri, priv->name ? priv->name : soup_address_get_physical (addr));
        soup_uri_set_port (uri, priv->port);
        soup_uri_set_path (uri, "");
-       uri_string = soup_uri_to_string_internal (uri, FALSE, TRUE);
+       uri_string = soup_uri_to_string_internal (uri, FALSE, FALSE, TRUE);
 
        proxy_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
                                   "connectable", connectable,
diff --git a/libsoup/soup-misc-private.h b/libsoup/soup-misc-private.h
index 6171ab8..be62e39 100644
--- a/libsoup/soup-misc-private.h
+++ b/libsoup/soup-misc-private.h
@@ -11,7 +11,7 @@
 
 char *soup_uri_decoded_copy (const char *str, int length, int *decoded_length);
 char *soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
-                                  gboolean force_port);
+                                  gboolean include_password, gboolean force_port);
 gboolean soup_uri_is_http (SoupURI *uri, char **aliases);
 gboolean soup_uri_is_https (SoupURI *uri, char **aliases);
 
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 0f02519..0513f7d 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -625,7 +625,7 @@ set_proxy_resolver (SoupSession *session, SoupURI *uri,
                char *uri_string;
 
                priv->proxy_uri = soup_uri_copy (uri);
-               uri_string = soup_uri_to_string_internal (uri, FALSE, TRUE);
+               uri_string = soup_uri_to_string_internal (uri, FALSE, TRUE, TRUE);
                priv->proxy_resolver = g_simple_proxy_resolver_new (uri_string, NULL);
                g_free (uri_string);
        } else if (soup_resolver) {
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index fbf2efb..3eafd87 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -530,7 +530,7 @@ soup_uri_new (const char *uri_string)
 
 char *
 soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
-                            gboolean force_port)
+                            gboolean include_password, gboolean force_port)
 {
        GString *str;
        char *return_result;
@@ -546,6 +546,10 @@ soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
                g_string_append (str, "//");
                if (uri->user) {
                        append_uri_encoded (str, uri->user, ":;@?/");
+                       if (uri->password && include_password) {
+                               g_string_append_c (str, ':');
+                               append_uri_encoded (str, uri->password, ";@?/");
+                       }
                        g_string_append_c (str, '@');
                }
                if (strchr (uri->host, ':')) {
@@ -611,7 +615,7 @@ soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
 char *
 soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
 {
-       return soup_uri_to_string_internal (uri, just_path_and_query, FALSE);
+       return soup_uri_to_string_internal (uri, just_path_and_query, FALSE, FALSE);
 }
 
 /**


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