[libsoup] soup-cache: Save the sniffed mime type in the cache too



commit 19a0f9a0f018b13028c9c860342ce62c4d83d1b6
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Jul 16 18:18:31 2012 +0200

    soup-cache: Save the sniffed mime type in the cache too
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680029

 libsoup/soup-cache.c        |   11 +++++++++++
 libsoup/soup-request-http.c |    3 ---
 2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index 95182f8..8b26478 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -101,6 +101,7 @@ typedef struct {
 	SoupCache *cache;
 	SoupCacheEntry *entry;
 	SoupMessage *msg;
+	gulong content_sniffed_handler;
 	gulong got_chunk_handler;
 	gulong got_body_handler;
 	gulong restarted_handler;
@@ -493,6 +494,8 @@ soup_cache_writing_fixture_free (SoupCacheWritingFixture *fixture)
 	/* Free fixture. And disconnect signals, we don't want to
 	   listen to more SoupMessage events as we're finished with
 	   this resource */
+	if (g_signal_handler_is_connected (fixture->msg, fixture->content_sniffed_handler))
+		g_signal_handler_disconnect (fixture->msg, fixture->content_sniffed_handler);
 	if (g_signal_handler_is_connected (fixture->msg, fixture->got_chunk_handler))
 		g_signal_handler_disconnect (fixture->msg, fixture->got_chunk_handler);
 	if (g_signal_handler_is_connected (fixture->msg, fixture->got_body_handler))
@@ -507,6 +510,12 @@ soup_cache_writing_fixture_free (SoupCacheWritingFixture *fixture)
 }
 
 static void
+msg_content_sniffed_cb (SoupMessage *msg, gchar *content_type, GHashTable *params, SoupCacheWritingFixture *fixture)
+{
+	soup_message_headers_set_content_type (fixture->entry->headers, content_type, params);
+}
+
+static void
 close_ready_cb (GObject *source, GAsyncResult *result, SoupCacheWritingFixture *fixture)
 {
 	SoupCacheEntry *entry = fixture->entry;
@@ -972,6 +981,8 @@ msg_got_headers_cb (SoupMessage *msg, gpointer user_data)
 
 		/* We connect now to these signals and buffer the data
 		   if it comes before the file is ready for writing */
+		fixture->content_sniffed_handler =
+			g_signal_connect (msg, "content-sniffed", G_CALLBACK (msg_content_sniffed_cb), fixture);
 		fixture->got_chunk_handler =
 			g_signal_connect (msg, "got-chunk", G_CALLBACK (msg_got_chunk_cb), fixture);
 		fixture->got_body_handler =
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index 319a591..44a1f7d 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -156,9 +156,6 @@ conditional_get_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_
 
 			soup_message_got_headers (sadata->original);
 
-			/* FIXME: this is wrong; the cache won't have
-			 * the sniffed type.
-			 */
 			sadata->http->priv->content_type = g_strdup (soup_message_headers_get_content_type (msg->response_headers, NULL));
 
 			g_simple_async_result_complete (sadata->simple);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]