diff options
author | Sergio Villar Senin <svillar@igalia.com> | 2010-12-09 13:32:41 +0100 |
---|---|---|
committer | Sergio Villar Senin <svillar@igalia.com> | 2010-12-09 17:26:09 +0100 |
commit | 22b8c97f41c9741fc2e97540fbbf87c1d798ca33 (patch) | |
tree | d39bd7b81a69059881ecc120220099d03a19038c /libsoup/soup-cache.c | |
parent | d2068e5f88de918c0e2b6122408c0e67fb280476 (diff) | |
download | libsoup-22b8c97f41c9741fc2e97540fbbf87c1d798ca33.tar.gz |
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.
Diffstat (limited to 'libsoup/soup-cache.c')
-rw-r--r-- | 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 05063489..f7d3bfb5 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 |