diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2019-11-09 16:59:26 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2019-11-09 16:59:26 +0000 |
commit | c92b31babea9f34a1987f99ce20a4c7b067f9b68 (patch) | |
tree | 6c21be3321e22884d6466f9e7d4182fc62facb37 /content/fetchers/resource.c | |
parent | e95c11dac89e39634aa9fa82a13ac780740122ee (diff) | |
download | netsurf-c92b31babea9f34a1987f99ce20a4c7b067f9b68.tar.gz netsurf-c92b31babea9f34a1987f99ce20a4c7b067f9b68.tar.bz2 |
Resource fetcher: Fix ETag handling.
* Changed ETag storage to be time_t, rather than int.
* Changed `If-None-Match` value parsing to use proper
time_t parsing, rather than `atoi`.
We emit FETCH_NOTMODIFIED if the resource hasn't changed.
Diffstat (limited to 'content/fetchers/resource.c')
-rw-r--r-- | content/fetchers/resource.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index 78757733e..94a51405d 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -33,6 +33,7 @@ #include "utils/nsurl.h" #include "utils/corestrings.h" #include "utils/log.h" +#include "utils/time.h" #include "utils/messages.h" #include "utils/utils.h" #include "utils/ring.h" @@ -97,7 +98,7 @@ struct fetch_resource_context { fetch_resource_handler handler; - int etag; + time_t etag; }; static struct fetch_resource_context *ring = NULL; @@ -328,6 +329,7 @@ fetch_resource_setup(struct fetch *fetchh, { struct fetch_resource_context *ctx; lwc_string *path; + nserror ret; uint32_t i; ctx = calloc(1, sizeof(*ctx)); @@ -364,17 +366,24 @@ fetch_resource_setup(struct fetch *fetchh, /* Scan request headers looking for If-None-Match */ for (i = 0; headers[i] != NULL; i++) { if (strncasecmp(headers[i], "If-None-Match:", - SLEN("If-None-Match:")) == 0) { - /* If-None-Match: "12345678" */ - const char *d = headers[i] + SLEN("If-None-Match:"); + SLEN("If-None-Match:")) != 0) { + continue; + } - /* Scan to first digit, if any */ - while (*d != '\0' && (*d < '0' || '9' < *d)) - d++; + /* If-None-Match: "12345678" */ + const char *d = headers[i] + SLEN("If-None-Match:"); - /* Convert to time_t */ - if (*d != '\0') - ctx->etag = atoi(d); + /* Scan to first digit, if any */ + while (*d != '\0' && (*d < '0' || '9' < *d)) + d++; + + /* Convert to time_t */ + if (*d != '\0') { + ret = nsc_snptimet(d, strlen(d), &ctx->etag); + if (ret != NSERROR_OK) { + NSLOG(fetch, WARNING, + "Bad If-None-Match value"); + } } } |