[libsoup] SoupCache: some issues in SoupCache (2/3)
- From: Sergio Villar Senin <svillar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] SoupCache: some issues in SoupCache (2/3)
- Date: Tue, 14 Feb 2012 12:37:42 +0000 (UTC)
commit e0a2af18a132e65b94c5033bc5142f9be2ddd616
Author: Sergio Villar Senin <svillar igalia com>
Date: Fri Jan 27 16:24:56 2012 +0100
SoupCache: some issues in SoupCache (2/3)
Do not generate conditional requests to revalidate resources if the server
has not provided neither "Last-Modified" nor "ETag" because the conditional
request could not be properly constructed in that case, and thus, we will
end up issuing two requests for the same resource.
https://bugzilla.gnome.org/show_bug.cgi?id=668865
libsoup/soup-cache.c | 36 ++++++++++++++++++++----------------
libsoup/soup-request-http.c | 12 +++++++-----
2 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index b001b98..4002a06 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -968,7 +968,7 @@ msg_got_headers_cb (SoupMessage *msg, gpointer user_data)
/* Check if we are already caching this resource */
entry = soup_cache_entry_lookup (cache, msg);
- if (entry && entry->dirty)
+ if (entry && (entry->dirty || entry->being_validated))
return;
/* Create a new entry, deleting any old one if present */
@@ -1550,12 +1550,24 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
SoupMessage *msg;
SoupURI *uri;
SoupCacheEntry *entry;
- const char *value;
+ const char *last_modified, *etag;
g_return_val_if_fail (SOUP_IS_CACHE (cache), NULL);
g_return_val_if_fail (SOUP_IS_MESSAGE (original), NULL);
- /* First copy the data we need from the original message */
+ /* Add the validator entries in the header from the cached data */
+ entry = soup_cache_entry_lookup (cache, original);
+ g_return_val_if_fail (entry, NULL);
+
+ last_modified = soup_message_headers_get_one (entry->headers, "Last-Modified");
+ etag = soup_message_headers_get_one (entry->headers, "ETag");
+
+ if (!last_modified && !etag)
+ return NULL;
+
+ entry->being_validated = TRUE;
+
+ /* Copy the data we need from the original message */
uri = soup_message_get_uri (original);
msg = soup_message_new_from_uri (original->method, uri);
@@ -1563,23 +1575,15 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
(SoupMessageHeadersForeachFunc)copy_headers,
msg->request_headers);
- /* Now add the validator entries in the header from the cached
- data */
- entry = soup_cache_entry_lookup (cache, original);
- g_return_val_if_fail (entry, NULL);
-
- entry->being_validated = TRUE;
-
- value = soup_message_headers_get (entry->headers, "Last-Modified");
- if (value)
+ if (last_modified)
soup_message_headers_append (msg->request_headers,
"If-Modified-Since",
- value);
- value = soup_message_headers_get (entry->headers, "ETag");
- if (value)
+ last_modified);
+ if (etag)
soup_message_headers_append (msg->request_headers,
"If-None-Match",
- value);
+ etag);
+
return msg;
}
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index e42a20a..89547e1 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -243,11 +243,13 @@ soup_request_http_send_async (SoupRequest *request,
conditional_msg = soup_cache_generate_conditional_request (cache, http->priv->msg);
- sadata->original = g_object_ref (http->priv->msg);
- soup_session_queue_message (session, conditional_msg,
- conditional_get_ready_cb,
- sadata);
- return;
+ if (conditional_msg) {
+ sadata->original = g_object_ref (http->priv->msg);
+ soup_session_queue_message (session, conditional_msg,
+ conditional_get_ready_cb,
+ sadata);
+ return;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]