[libsoup] soup-cache: update state of SoupMessages when returning data from the cache



commit 5743afe84ad3bbad4c9e8876ddba8136ea4eb430
Author: Sergio Villar Senin <svillar igalia com>
Date:   Wed Jun 8 09:18:07 2011 +0200

    soup-cache: update state of SoupMessages when returning data from the cache
    
    SoupCache generates conditional requests to validate some resources. As the
    cache is transparent for the client it must update the state of the
    SoupMessage used by the SoupHTTPRequest as if the message was really
    transmitted over the network. SoupCache was not updating the state
    (basically status code and headers) of the SoupMessage that belongs to the
    SoupHTTPRequest but the one used for freshness validation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=649965

 libsoup/soup-cache.c        |   22 +++++++++++++---------
 libsoup/soup-request-http.c |    5 +++--
 2 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index 70d865a..5816e58 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -1008,6 +1008,19 @@ soup_cache_send_response (SoupCache *cache, SoupMessage *msg)
 	g_free (key);
 	g_return_val_if_fail (entry, NULL);
 
+	/* TODO: the original idea was to save reads, but current code
+	   assumes that a stream is always returned. Need to reach
+	   some agreement here. Also we have to handle the situation
+	   were the file was no longer there (for example files
+	   removed without notifying the cache */
+	file = g_file_new_for_path (entry->filename);
+	stream = G_INPUT_STREAM (g_file_read (file, NULL, NULL));
+	g_object_unref (file);
+
+	/* Do not change the original message if there is no resource */
+	if (stream == NULL)
+		return stream;
+
 	/* If we are told to send a response from cache any validation
 	   in course is over by now */
 	entry->being_validated = FALSE;
@@ -1022,15 +1035,6 @@ soup_cache_send_response (SoupCache *cache, SoupMessage *msg)
 				      current_age);
 	g_free (current_age);
 
-	/* TODO: the original idea was to save reads, but current code
-	   assumes that a stream is always returned. Need to reach
-	   some agreement here. Also we have to handle the situation
-	   were the file was no longer there (for example files
-	   removed without notifying the cache */
-	file = g_file_new_for_path (entry->filename);
-	stream = G_INPUT_STREAM (g_file_read (file, NULL, NULL));
-	g_object_unref (file);
-
 	return stream;
 }
 
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index 42cc6e0..8ef95fc 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -133,14 +133,15 @@ conditional_get_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_
 	if (msg->status_code == SOUP_STATUS_NOT_MODIFIED) {
 		SoupCache *cache = (SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE);
 
-		httpstream = (SoupHTTPInputStream *)soup_cache_send_response (cache, msg);
+		httpstream = (SoupHTTPInputStream *)soup_cache_send_response (cache, helper->original);
 		if (httpstream) {
 			g_simple_async_result_set_op_res_gpointer (simple, httpstream, g_object_unref);
 
 			soup_message_got_headers (helper->original);
 
 			if (soup_session_get_feature_for_message (session, SOUP_TYPE_CONTENT_SNIFFER, helper->original)) {
-			 	const char *content_type = soup_message_headers_get_content_type (msg->response_headers, NULL);
+				const char *content_type =
+					soup_message_headers_get_content_type (helper->original->response_headers, NULL);
 			 	soup_message_content_sniffed (helper->original, content_type, NULL);
 			}
 



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