Fix Host header syntax when the host is an IPv6 address literal. Noticed
authorDan Winship <danw@src.gnome.org>
Fri, 14 Mar 2008 23:10:57 +0000 (23:10 +0000)
committerDan Winship <danw@src.gnome.org>
Fri, 14 Mar 2008 23:10:57 +0000 (23:10 +0000)
* libsoup/soup-message-client-io.c (get_request_headers): Fix Host
header syntax when the host is an IPv6 address literal. Noticed
while poking at #522519.

svn path=/trunk/; revision=1109

ChangeLog
libsoup/soup-message-client-io.c

index d5579a5..4eef5e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-03-14  Dan Winship  <danw@gnome.org>
 
+       * libsoup/soup-message-client-io.c (get_request_headers): Fix Host
+       header syntax when the host is an IPv6 address literal. Noticed
+       while poking at #522519.
+
+2008-03-14  Dan Winship  <danw@gnome.org>
+
        * libsoup/soup-message-private.h (SoupMessagePrivate): add
        an orig_http_version field.
 
index 4ffbd72..4906f64 100644 (file)
@@ -66,13 +66,19 @@ get_request_headers (SoupMessage *req, GString *header,
        SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (req);
        gboolean proxy = GPOINTER_TO_UINT (user_data);
        SoupURI *uri = soup_message_get_uri (req);
+       char *uri_host;
        char *uri_string;
        SoupMessageHeadersIter iter;
        const char *name, *value;
 
+       if (strchr (uri->host, ':'))
+               uri_host = g_strdup_printf ("[%s]", uri->host);
+       else
+               uri_host = uri->host;
+
        if (req->method == SOUP_METHOD_CONNECT) {
                /* CONNECT URI is hostname:port for tunnel destination */
-               uri_string = g_strdup_printf ("%s:%d", uri->host, uri->port);
+               uri_string = g_strdup_printf ("%s:%d", uri_host, uri->port);
        } else {
                /* Proxy expects full URI to destination. Otherwise
                 * just the path.
@@ -88,13 +94,15 @@ get_request_headers (SoupMessage *req, GString *header,
                                        req->method, uri_string);
                if (soup_uri_uses_default_port (uri)) {
                        g_string_append_printf (header, "Host: %s\r\n",
-                                               uri->host);
+                                               uri_host);
                } else {
                        g_string_append_printf (header, "Host: %s:%d\r\n",
-                                               uri->host, uri->port);
+                                               uri_host, uri->port);
                }
        }
        g_free (uri_string);
+       if (uri_host != uri->host)
+               g_free (uri_host);
 
        *encoding = soup_message_headers_get_encoding (req->request_headers);
        if (*encoding != SOUP_ENCODING_CHUNKED &&