summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2019-06-10 20:56:23 +0000
committerJohn-Mark Bell <jmb@netsurf-browser.org>2019-06-10 21:02:26 +0000
commit047c82cfce53102aced0f76f5ca13fe3c56b4db2 (patch)
tree98ea94cd6e45d2271e93d02cc283224b80955d3b
parent04b790643b9e45a1ba8919481f3c4beb80a66c31 (diff)
downloadnetsurf-047c82cfce53102aced0f76f5ca13fe3c56b4db2.tar.gz
netsurf-047c82cfce53102aced0f76f5ca13fe3c56b4db2.tar.bz2
LLCache: use Cache-Control parser
-rw-r--r--content/llcache.c66
1 files changed, 18 insertions, 48 deletions
diff --git a/content/llcache.c b/content/llcache.c
index 0bf3979a0..d78d5bb62 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -45,6 +45,7 @@
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "utils/time.h"
+#include "utils/http.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
@@ -583,59 +584,28 @@ static nserror llcache_fetch_split_header(const uint8_t *data, size_t len,
static nserror
llcache_fetch_parse_cache_control(llcache_object *object, char *value)
{
- const char *start = value;
- const char *comma = value;
-
- while (*comma != '\0') {
- while (*comma != '\0' && *comma != ',') {
- comma++;
- }
-
- if ((8 < comma - start) &&
- (strncasecmp(start, "no-cache", 8) == 0 ||
- strncasecmp(start, "no-store", 8) == 0)) {
- /**
- * \todo When we get a disk cache we should
- * distinguish between these two.
- */
- object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
- } else if ((7 < comma - start) &&
- strncasecmp(start, "max-age", 7) == 0) {
- start += 7; /* skip max-age */
-
- /* Find '=' */
- while (start < comma && *start != '=') {
- start++;
- }
-
- /* Skip over '=' */
- start++;
-
-#define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++
-
- if (start < comma) {
- /* Skip whitespace */
- SKIP_ST(start);
- }
+ http_cache_control *cc;
+ nserror error;
- if (start < comma) {
- object->cache.max_age = atoi(start);
+ error = http_parse_cache_control(value, &cc);
+ if (error != NSERROR_OK) {
+ /* Ignore parse errors */
+ return NSERROR_OK;
+ }
- }
- }
+ if (http_cache_control_no_cache(cc) ||
+ http_cache_control_no_store(cc)) {
+ /**
+ * \todo When we get a disk cache we should
+ * distinguish between these two.
+ */
+ object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
+ }
- if (*comma != '\0') {
- /* Skip past comma */
- comma++;
- /* Skip whitespace */
- SKIP_ST(comma);
- }
+ object->cache.max_age = http_cache_control_max_age(cc);
-#undef SKIP_ST
+ http_cache_control_destroy(cc);
- /* Set start for next token */
- start = comma;
- }
return NSERROR_OK;
}