[libsoup] Cache must not return a cached resource with "no-cache" directive
- From: Sergio Villar Senin <svillar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Cache must not return a cached resource with "no-cache" directive
- Date: Thu, 9 Dec 2010 16:31:18 +0000 (UTC)
commit 22b8c97f41c9741fc2e97540fbbf87c1d798ca33
Author: Sergio Villar Senin <svillar igalia com>
Date: Thu Dec 9 13:32:41 2010 +0100
Cache must not return a cached resource with "no-cache" directive
If "Pragma: no-cache" or "Cache-Control: no-cache" do exist in a request then
the cache must not return a cached resource but reload the resource from the
original server.
A "Cache-Control: max-age=0" should also force the cache to revalidate its
entries against the original server.
libsoup/soup-cache.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index 0506348..f7d3bfb 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -1252,7 +1252,7 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
{
char *key;
SoupCacheEntry *entry;
- const char *cache_control;
+ const char *cache_control, *pragma;
gpointer value;
gboolean must_revalidate;
int max_age, max_stale, min_fresh;
@@ -1315,6 +1315,12 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
must_revalidate = FALSE;
max_age = max_stale = min_fresh = -1;
+ /* For HTTP 1.0 compatibility. RFC2616 section 14.9.4
+ */
+ pragma = soup_message_headers_get (msg->request_headers, "Pragma");
+ if (pragma && soup_header_contains (pragma, "no-cache"))
+ return SOUP_CACHE_RESPONSE_STALE;
+
cache_control = soup_message_headers_get (msg->request_headers, "Cache-Control");
if (cache_control) {
GHashTable *hash = soup_header_parse_param_list (cache_control);
@@ -1325,11 +1331,16 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
}
if (g_hash_table_lookup_extended (hash, "no-cache", NULL, NULL)) {
- entry->must_revalidate = TRUE;
+ soup_header_free_param_list (hash);
+ return SOUP_CACHE_RESPONSE_STALE;
}
if (g_hash_table_lookup_extended (hash, "max-age", NULL, &value)) {
max_age = (int)MIN (g_ascii_strtoll (value, NULL, 10), G_MAXINT32);
+ /* Forcing cache revalidaton
+ */
+ if (!max_age)
+ entry->must_revalidate = TRUE;
}
/* max-stale can have no value set, we need to use _extended */
@@ -1346,7 +1357,7 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
soup_header_free_param_list (hash);
- if (max_age != -1) {
+ if (max_age > 0) {
guint current_age = soup_cache_entry_get_current_age (entry);
/* If we are over max-age and max-stale is not
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]