2009-03-06 Gustavo Noronha Silva <gns@gnome.org>
authorkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2009 15:54:58 +0000 (15:54 +0000)
committerkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2009 15:54:58 +0000 (15:54 +0000)
        Reviewed by Holger Freyther.

        https://bugs.webkit.org/show_bug.cgi?id=24051
        Soup backend needs content sniffing capabilities

        Perform content sniffing when using soup, so that we have a chance
        of figuring out the Content-Type of the file if it's not sent by
        the server.

        * platform/network/ResourceHandleInternal.h:
        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
        * platform/network/soup/ResourceHandleSoup.cpp:
        (WebCore::gotHeadersCallback):
        (WebCore::gotChunkCallback):

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

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

index 614e0db..e0c8ab1 100644 (file)
@@ -1,3 +1,20 @@
+2009-03-06  Gustavo Noronha Silva  <gns@gnome.org>
+
+        Reviewed by Holger Freyther.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24051
+        Soup backend needs content sniffing capabilities
+
+        Perform content sniffing when using soup, so that we have a chance
+        of figuring out the Content-Type of the file if it's not sent by
+        the server.
+
+        * platform/network/ResourceHandleInternal.h:
+        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::gotHeadersCallback):
+        (WebCore::gotChunkCallback):
+
 2009-03-06  Hironori Bono  <hbono@chromium.org>
 
         Reviewed by Alexey Proskuryakov.
 2009-03-06  Hironori Bono  <hbono@chromium.org>
 
         Reviewed by Alexey Proskuryakov.
index a55f945..875854b 100644 (file)
@@ -111,6 +111,7 @@ namespace WebCore {
 #if USE(SOUP)
             , m_msg(0)
             , m_cancelled(false)
 #if USE(SOUP)
             , m_msg(0)
             , m_cancelled(false)
+            , m_reportedHeaders(false)
             , m_gfile(0)
             , m_inputStream(0)
             , m_cancellable(0)
             , m_gfile(0)
             , m_inputStream(0)
             , m_cancellable(0)
@@ -183,6 +184,7 @@ namespace WebCore {
         SoupMessage* m_msg;
         ResourceResponse m_response;
         bool m_cancelled;
         SoupMessage* m_msg;
         ResourceResponse m_response;
         bool m_cancelled;
+        bool m_reportedHeaders;
         GFile* m_gfile;
         GInputStream* m_inputStream;
         GCancellable* m_cancellable;
         GFile* m_gfile;
         GInputStream* m_inputStream;
         GCancellable* m_cancellable;
index 82ed142..2169450 100644 (file)
@@ -214,6 +214,14 @@ static void gotHeadersCallback(SoupMessage* msg, gpointer data)
     if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
         return;
 
     if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
         return;
 
+    soup_message_set_flags(msg, SOUP_MESSAGE_OVERWRITE_CHUNKS);
+
+    // We still don't know anything about Content-Type, so we will try
+    // sniffing the contents of the file, and then report that we got
+    // headers
+    if (!soup_message_headers_get_content_type(msg->response_headers, NULL))
+        return;
+
     ResourceHandle* handle = static_cast<ResourceHandle*>(data);
     if (!handle)
         return;
     ResourceHandle* handle = static_cast<ResourceHandle*>(data);
     if (!handle)
         return;
@@ -226,7 +234,7 @@ static void gotHeadersCallback(SoupMessage* msg, gpointer data)
 
     fillResponseFromMessage(msg, &d->m_response);
     client->didReceiveResponse(handle, d->m_response);
 
     fillResponseFromMessage(msg, &d->m_response);
     client->didReceiveResponse(handle, d->m_response);
-    soup_message_set_flags(msg, SOUP_MESSAGE_OVERWRITE_CHUNKS);
+    d->m_reportedHeaders = true;
 }
 
 static void gotChunkCallback(SoupMessage* msg, SoupBuffer* chunk, gpointer data)
 }
 
 static void gotChunkCallback(SoupMessage* msg, SoupBuffer* chunk, gpointer data)
@@ -244,6 +252,17 @@ static void gotChunkCallback(SoupMessage* msg, SoupBuffer* chunk, gpointer data)
     if (!client)
         return;
 
     if (!client)
         return;
 
+    if (!d->m_reportedHeaders) {
+        gboolean uncertain;
+        char* contentType = g_content_type_guess(d->m_request.url().lastPathComponent().utf8().data(), reinterpret_cast<const guchar*>(chunk->data), chunk->length, &uncertain);
+        soup_message_headers_set_content_type(msg->response_headers, contentType, NULL);
+        g_free(contentType);
+
+        fillResponseFromMessage(msg, &d->m_response);
+        client->didReceiveResponse(handle, d->m_response);
+        d->m_reportedHeaders = true;
+    }
+
     client->didReceiveData(handle, chunk->data, chunk->length, false);
 }
 
     client->didReceiveData(handle, chunk->data, chunk->length, false);
 }