summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-04-18 10:30:32 -0400
committerDan Winship <danw@gnome.org>2013-04-24 11:28:18 -0400
commit3943610faed4922b739162f244f32e0b2393cba0 (patch)
treeede9e51ffb3e3b847450c5a768501f594dc3e40e
parent2a28ddf6b34546b0f5ca82ce5152612a44a6cd50 (diff)
downloadlibsoup-3943610faed4922b739162f244f32e0b2393cba0.tar.gz
libsoup-3943610faed4922b739162f244f32e0b2393cba0.tar.bz2
libsoup-3943610faed4922b739162f244f32e0b2393cba0.zip
soup-address: fix proxy enumerator implementation
When creating a GProxyAddressEnumerator, the destination URI passed to it must include the port number, or the proxy may end up trying to connect to port 0. libsoup was omitting the port number when it was the default for the protocol. https://bugzilla.gnome.org/show_bug.cgi?id=698163
-rw-r--r--libsoup/soup-address.c3
-rw-r--r--libsoup/soup-misc-private.h2
-rw-r--r--libsoup/soup-uri.c39
3 files changed, 27 insertions, 17 deletions
diff --git a/libsoup/soup-address.c b/libsoup/soup-address.c
index e1696fb0..286be8c7 100644
--- a/libsoup/soup-address.c
+++ b/libsoup/soup-address.c
@@ -14,6 +14,7 @@
#include "soup-address.h"
#include "soup.h"
#include "soup-marshal.h"
+#include "soup-misc-private.h"
/**
* SECTION:soup-address
@@ -1209,7 +1210,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 (uri, FALSE);
+ uri_string = soup_uri_to_string_internal (uri, 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 cd836189..d03bc77f 100644
--- a/libsoup/soup-misc-private.h
+++ b/libsoup/soup-misc-private.h
@@ -10,6 +10,8 @@
#include "soup-socket.h"
char *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);
guint soup_socket_handshake_sync (SoupSocket *sock,
GCancellable *cancellable);
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 723e3610..26ec24a0 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -489,21 +489,9 @@ soup_uri_new (const char *uri_string)
}
-/**
- * soup_uri_to_string:
- * @uri: a #SoupURI
- * @just_path_and_query: if %TRUE, output just the path and query portions
- *
- * Returns a string representing @uri.
- *
- * If @just_path_and_query is %TRUE, this concatenates the path and query
- * together. That is, it constructs the string that would be needed in
- * the Request-Line of an HTTP request for @uri.
- *
- * Return value: a string representing @uri, which the caller must free.
- **/
char *
-soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
+soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
+ gboolean force_port)
{
GString *str;
char *return_result;
@@ -511,7 +499,7 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
g_return_val_if_fail (uri != NULL, NULL);
g_warn_if_fail (SOUP_URI_IS_VALID (uri));
- str = g_string_sized_new (20);
+ str = g_string_sized_new (40);
if (uri->scheme && !just_path_and_query)
g_string_append_printf (str, "%s:", uri->scheme);
@@ -527,7 +515,7 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
g_string_append_c (str, ']');
} else
append_uri_encoded (str, uri->host, ":/");
- if (uri->port && uri->port != soup_scheme_default_port (uri->scheme))
+ if (uri->port && (force_port || uri->port != soup_scheme_default_port (uri->scheme)))
g_string_append_printf (str, ":%u", uri->port);
if (!uri->path && (uri->query || uri->fragment))
g_string_append_c (str, '/');
@@ -558,6 +546,25 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
}
/**
+ * soup_uri_to_string:
+ * @uri: a #SoupURI
+ * @just_path_and_query: if %TRUE, output just the path and query portions
+ *
+ * Returns a string representing @uri.
+ *
+ * If @just_path_and_query is %TRUE, this concatenates the path and query
+ * together. That is, it constructs the string that would be needed in
+ * the Request-Line of an HTTP request for @uri.
+ *
+ * Return value: a string representing @uri, which the caller must free.
+ **/
+char *
+soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
+{
+ return soup_uri_to_string_internal (uri, just_path_and_query, FALSE);
+}
+
+/**
* soup_uri_copy:
* @uri: a #SoupURI
*