SoupCache: some issues in SoupCache (1/3)
authorSergio Villar Senin <svillar@igalia.com>
Fri, 27 Jan 2012 13:06:41 +0000 (14:06 +0100)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 14 Feb 2012 11:21:56 +0000 (12:21 +0100)
Respect section 13.9 from specs. Resources whose URL has a query and do not
have expiration time provided by the server must not be cached.

https://bugzilla.gnome.org/show_bug.cgi?id=668865

libsoup/soup-cache.c

index e970bcb..b001b98 100644 (file)
@@ -147,6 +147,7 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
 {
        SoupCacheability cacheability;
        const char *cache_control, *content_type;
+       gboolean has_max_age = FALSE;
 
        /* 1. The request method must be cacheable */
        if (msg->method == SOUP_METHOD_GET)
@@ -185,6 +186,9 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
                        return SOUP_CACHE_UNCACHEABLE;
                }
 
+               if (g_hash_table_lookup_extended (hash, "max-age", NULL, NULL))
+                       has_max_age = TRUE;
+
                /* This does not appear in section 2.1, but I think it makes
                 * sense to check it too?
                 */
@@ -196,6 +200,12 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
                soup_header_free_param_list (hash);
        }
 
+       /* Section 13.9 */
+       if ((soup_message_get_uri (msg))->query &&
+           !soup_message_headers_get_one (msg->response_headers, "Expires") &&
+           !has_max_age)
+               return SOUP_CACHE_UNCACHEABLE;
+
        switch (msg->status_code) {
        case SOUP_STATUS_PARTIAL_CONTENT:
                /* We don't cache partial responses, but they only