From e724672302fe0e44ed431888903223c200cf8f8f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 8 Feb 2006 00:35:05 +0000 Subject: [project @ 2006-02-08 00:35:05 by jmb] Handle case where no cache expiry headers are sent; use (now - last_modified) / 10. This should reduce the frequency of cache entry validation. svn path=/import/netsurf/; revision=2064 --- content/content.c | 1 + content/fetch.c | 11 +++++++++++ content/fetch.h | 1 + content/fetchcache.c | 15 ++++++++++----- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/content/content.c b/content/content.c index 9b5d3c8f2..adf0cb6c8 100644 --- a/content/content.c +++ b/content/content.c @@ -328,6 +328,7 @@ struct content * content_create(const char *url) c->cache_data->max_age = INVALID_AGE; c->cache_data->no_cache = false; c->cache_data->etag = 0; + c->cache_data->last_modified = 0; c->prev = 0; c->next = content_list; diff --git a/content/fetch.c b/content/fetch.c index 9f1b93652..bbe4d3402 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -285,6 +285,7 @@ struct fetch * fetch_start(char *url, char *referer, fetch->cachedata.max_age = INVALID_AGE; fetch->cachedata.no_cache = false; fetch->cachedata.etag = 0; + fetch->cachedata.last_modified = 0; fetch->last_modified = 0; fetch->file_etag = 0; fetch->queue_prev = 0; @@ -868,6 +869,13 @@ size_t fetch_curl_header(char *data, size_t size, size_t nmemb, f->cachedata.etag[i] == '\r' || f->cachedata.etag[i] == '\n'); --i) f->cachedata.etag[i] = '\0'; + } else if (14 < size && strncasecmp(data, "Last-Modified:", 14) == 0) { + /* extract Last-Modified header */ + SKIP_ST(14); + if (i < (int) size) { + f->cachedata.last_modified = + curl_getdate(&data[i], NULL); + } } return size; @@ -948,6 +956,9 @@ bool fetch_process_headers(struct fetch *f) sprintf(f->cachedata.etag, "\"%10d\"", (int)s.st_mtime); + /* don't set last modified time so as to ensure that local + * files are revalidated at all times. */ + /* If performed a conditional request and unmodified ... */ if (f->last_modified && f->file_etag && f->last_modified > s.st_mtime && diff --git a/content/fetch.h b/content/fetch.h index b65e150ff..633a87131 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -43,6 +43,7 @@ struct cache_data { int max_age; /**< Max-age Cache-control parameter */ bool no_cache; /**< no-cache Cache-control parameter */ char *etag; /**< Etag: response header */ + time_t last_modified; /**< Last-Modified: response header */ }; extern bool fetch_active; diff --git a/content/fetchcache.c b/content/fetchcache.c index 6e3f359f0..62fa07e3f 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -111,7 +111,9 @@ struct content * fetchcache(const char *url, freshness_lifetime = (cd->max_age != INVALID_AGE) ? cd->max_age : (cd->expires != 0) ? cd->expires - cd->date : - 0; + (cd->last_modified != 0) ? + (time(0) - cd->last_modified) / 10 : + 0; if (freshness_lifetime > current_age || cd->date == 0) { @@ -127,10 +129,10 @@ struct content * fetchcache(const char *url, /* Ok. We have a cache entry, but it appears stale. * Therefore, validate it. */ - /** \todo perhaps it'd be better to use the - * contents of the Last-Modified header here - * instead */ - date = c->cache_data->date; + if (cd->last_modified) + date = cd->last_modified; + else + date = c->cache_data->date; etag = c->cache_data->etag; } } @@ -585,6 +587,9 @@ void fetchcache_cache_update(struct content *c, talloc_free(c->cache_data->etag); c->cache_data->etag = talloc_strdup(c, data->etag); } + + if (data->last_modified) + c->cache_data->last_modified = data->last_modified; } -- cgit v1.2.3