soup-multipart: don't quote the boundary string if it doesn't need it
authorDan Winship <danw@gnome.org>
Tue, 6 Apr 2010 16:08:59 +0000 (12:08 -0400)
committerDan Winship <danw@gnome.org>
Fri, 9 Apr 2010 23:51:33 +0000 (19:51 -0400)
RFC 2616 warns that some HTTP implementations misparse quoted boundary
parameters in multipart Content-Type headers. (Sigh.) Since our
boundary strings are tokens, they don't need to be quoted anyway
(although if we parse and then later reserialize a multipart generated
by someone else, we may still need to quote it).

https://bugzilla.gnome.org/show_bug.cgi?id=614176

libsoup/soup-multipart.c

index dd0287c..f825a9d 100644 (file)
@@ -423,15 +423,15 @@ soup_multipart_to_message (SoupMultipart *multipart,
        SoupMessageHeadersIter iter;
        const char *name, *value;
        GString *str;
-       char *content_type;
+       GHashTable *params;
        int i;
 
-       content_type = g_strdup_printf ("%s; boundary=\"%s\"",
-                                       multipart->mime_type,
-                                       multipart->boundary);
-       soup_message_headers_replace (dest_headers, "Content-Type",
-                                     content_type);
-       g_free (content_type);
+       params = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_insert (params, "boundary", multipart->boundary);
+       soup_message_headers_set_content_type (dest_headers,
+                                              multipart->mime_type,
+                                              params);
+       g_hash_table_destroy (params);
 
        for (i = 0; i < multipart->bodies->len; i++) {
                part_headers = multipart->headers->pdata[i];