[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
This commit is contained in:
parent
04e7ec32f9
commit
e724672302
|
@ -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;
|
||||
|
|
|
@ -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 &&
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue