summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2006-02-08 00:35:05 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2006-02-08 00:35:05 +0000
commite724672302fe0e44ed431888903223c200cf8f8f (patch)
treec160669ae9167a8b9e4f8baf985fea77132402b6
parent04e7ec32f9182847a7edc6429bb856f5f086e263 (diff)
downloadnetsurf-e724672302fe0e44ed431888903223c200cf8f8f.tar.gz
netsurf-e724672302fe0e44ed431888903223c200cf8f8f.tar.bz2
[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
-rw-r--r--content/content.c1
-rw-r--r--content/fetch.c11
-rw-r--r--content/fetch.h1
-rw-r--r--content/fetchcache.c15
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;
}