From d8d0353a734767fcc1211b922820a59303e810a5 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 17 Feb 2011 17:50:14 +0000 Subject: Fix bug #3184972: cope with server sending a 304 in response to an unconditional request. svn path=/trunk/netsurf/; revision=11710 --- content/llcache.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'content/llcache.c') diff --git a/content/llcache.c b/content/llcache.c index cf409849a..64e37915a 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -2064,23 +2064,38 @@ nserror llcache_fetch_redirect(llcache_object *object, const char *target, nserror llcache_fetch_notmodified(llcache_object *object, llcache_object **replacement) { - llcache_object_user *user, *next; + /* There may be no candidate if the server erroneously responded + * to an unconditional request with a 304 Not Modified response. + * In this case, we simply retain the initial object, having + * invalidated it and marked it as complete. + */ + if (object->candidate != NULL) { + llcache_object_user *user, *next; - /* Move user(s) to candidate content */ - for (user = object->users; user != NULL; user = next) { - next = user->next; + /* Move user(s) to candidate content */ + for (user = object->users; user != NULL; user = next) { + next = user->next; - llcache_object_remove_user(object, user); - llcache_object_add_user(object->candidate, user); - } + llcache_object_remove_user(object, user); + llcache_object_add_user(object->candidate, user); + } + + /* Candidate is no longer a candidate for us */ + object->candidate->candidate_count--; - /* Candidate is no longer a candidate for us */ - object->candidate->candidate_count--; + /* Clone our cache control data into the candidate */ + llcache_object_clone_cache_data(object, object->candidate, + false); + /* Bring candidate's cache data up to date */ + llcache_object_cache_update(object->candidate); - /* Clone our cache control data into the candidate */ - llcache_object_clone_cache_data(object, object->candidate, false); - /* Bring candidate's cache data up to date */ - llcache_object_cache_update(object->candidate); + /* Candidate is now our object */ + *replacement = object->candidate; + object->candidate = NULL; + } else { + /* There was no candidate: retain object */ + *replacement = object; + } /* Ensure fetch has stopped */ fetch_abort(object->fetch.fetch); @@ -2092,10 +2107,6 @@ nserror llcache_fetch_notmodified(llcache_object *object, /* Mark it complete */ object->fetch.state = LLCACHE_FETCH_COMPLETE; - /* Candidate is now our object */ - *replacement = object->candidate; - object->candidate = NULL; - /* Old object will be flushed from the cache on the next poll */ return NSERROR_OK; -- cgit v1.2.3