2009-03-25 Gustavo Noronha Silva <gns@gnome.org>
authorkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2009 15:09:24 +0000 (15:09 +0000)
committerkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2009 15:09:24 +0000 (15:09 +0000)
        Reviewed by Holger Freyther.

        https://bugs.webkit.org/show_bug.cgi?id=24750
        [GTK] requests download instead of displaying page

        Fix the Content-Type headers we get from soup, so that we set a
        proper media type on the ResourceResponse.

        * platform/network/soup/ResourceHandleSoup.cpp:
        (WebCore::fillResponseFromMessage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@41975 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/network/soup/ResourceHandleSoup.cpp

index 1182eac..03b7af7 100644 (file)
@@ -2,6 +2,19 @@
 
         Reviewed by Holger Freyther.
 
 
         Reviewed by Holger Freyther.
 
+        https://bugs.webkit.org/show_bug.cgi?id=24750
+        [GTK] requests download instead of displaying page
+
+        Fix the Content-Type headers we get from soup, so that we set a
+        proper media type on the ResourceResponse.
+
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::fillResponseFromMessage):
+
+2009-03-25  Gustavo Noronha Silva  <gns@gnome.org>
+
+        Reviewed by Holger Freyther.
+
         https://bugs.webkit.org/show_bug.cgi?id=24600
         [GTK] responses with status code >= 400 should not be given special treatment
 
         https://bugs.webkit.org/show_bug.cgi?id=24600
         [GTK] responses with status code >= 400 should not be given special treatment
 
index de5168f..b723c4b 100644 (file)
@@ -159,11 +159,37 @@ static void fillResponseFromMessage(SoupMessage* msg, ResourceResponse* response
     while (soup_message_headers_iter_next(&iter, &name, &value))
         response->setHTTPHeaderField(name, value);
 
     while (soup_message_headers_iter_next(&iter, &name, &value))
         response->setHTTPHeaderField(name, value);
 
-    String contentType = soup_message_headers_get(msg->response_headers, "Content-Type");
+    GHashTable* contentTypeParameters = 0;
+    String contentType = soup_message_headers_get_content_type(msg->response_headers, &contentTypeParameters);
+
+    // When the server sends multiple Content-Type headers, soup will
+    // give us their values concatenated with commas as a separator;
+    // we need to handle this and use only one value. We use the first
+    // value, and add all the parameters, afterwards, if any.
+    Vector<String> contentTypes;
+    contentType.split(',', true, contentTypes);
+    contentType = contentTypes[0];
+
+    if (contentTypeParameters) {
+        GHashTableIter hashTableIter;
+        gpointer hashKey;
+        gpointer hashValue;
+
+        g_hash_table_iter_init(&hashTableIter, contentTypeParameters);
+        while (g_hash_table_iter_next(&hashTableIter, &hashKey, &hashValue)) {
+            contentType += String("; ");
+            contentType += String(static_cast<char*>(hashKey));
+            contentType += String("=");
+            contentType += String(static_cast<char*>(hashValue));
+        }
+        g_hash_table_destroy(contentTypeParameters);
+    }
+
+    response->setMimeType(extractMIMETypeFromMediaType(contentType));
+
     char* uri = soup_uri_to_string(soup_message_get_uri(msg), false);
     response->setURL(KURL(KURL(), uri));
     g_free(uri);
     char* uri = soup_uri_to_string(soup_message_get_uri(msg), false);
     response->setURL(KURL(KURL(), uri));
     g_free(uri);
-    response->setMimeType(extractMIMETypeFromMediaType(contentType));
     response->setTextEncodingName(extractCharsetFromMediaType(contentType));
     response->setExpectedContentLength(soup_message_headers_get_content_length(msg->response_headers));
     response->setHTTPStatusCode(msg->status_code);
     response->setTextEncodingName(extractCharsetFromMediaType(contentType));
     response->setExpectedContentLength(soup_message_headers_get_content_length(msg->response_headers));
     response->setHTTPStatusCode(msg->status_code);