summaryrefslogtreecommitdiff
path: root/content/llcache.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2019-11-10 16:03:07 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2019-11-10 16:49:05 +0000
commit26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7 (patch)
tree2e3e406f2ed816581a09affd7a2ebe78927aaee4 /content/llcache.c
parentc14f01ea442295e2d658a1f9bec866c5638bb3ca (diff)
downloadnetsurf-26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7.tar.gz
netsurf-26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7.tar.bz2
llcache: Split out scheme is cachable check.
Diffstat (limited to 'content/llcache.c')
-rw-r--r--content/llcache.c65
1 files changed, 38 insertions, 27 deletions
diff --git a/content/llcache.c b/content/llcache.c
index e79411279..f34286603 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -1520,6 +1520,43 @@ format_error:
}
/**
+ * Check whether a scheme is cachable.
+ *
+ * \param url URL to check.
+ * \return true iff url has a cachable scheme.
+ */
+static inline bool llcache__scheme_is_cachable(const nsurl *url)
+{
+ lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME);
+ bool cachable = false;
+ bool match;
+
+ /* nsurl ensures lower case schemes, and corestrings are lower
+ * case, so it's safe to use case-sensitive comparison. */
+ if ((lwc_string_isequal(scheme, corestring_lwc_http,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_https,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_data,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_resource,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_file,
+ &match) == lwc_error_ok &&
+ (match == true))) {
+ cachable = true;
+ }
+
+ lwc_string_unref(scheme);
+
+ return cachable;
+}
+
+/**
* Attempt to retrieve an object from persistent storage.
*
* \param object The object to populate from persistent store.
@@ -1792,35 +1829,9 @@ llcache_object_retrieve(nsurl *url,
/* POST requests are never cached */
uncachable = true;
} else {
- /* only http(s), data, resource, and file schemes are cached */
- lwc_string *scheme;
- bool match;
-
- scheme = nsurl_get_component(defragmented_url, NSURL_SCHEME);
-
- /* nsurl ensures lower case schemes, and corestrings are lower
- * case, so it's safe to use case-sensitive comparison. */
- if (lwc_string_isequal(scheme, corestring_lwc_http,
- &match) == lwc_error_ok &&
- (match == false) &&
- lwc_string_isequal(scheme, corestring_lwc_https,
- &match) == lwc_error_ok &&
- (match == false) &&
- lwc_string_isequal(scheme, corestring_lwc_data,
- &match) == lwc_error_ok &&
- (match == false) &&
- lwc_string_isequal(scheme, corestring_lwc_resource,
- &match) == lwc_error_ok &&
- (match == false) &&
- lwc_string_isequal(scheme, corestring_lwc_file,
- &match) == lwc_error_ok &&
- (match == false)) {
- uncachable = true;
- }
- lwc_string_unref(scheme);
+ uncachable = !llcache__scheme_is_cachable(defragmented_url);
}
-
if (uncachable) {
/* Create new object */
error = llcache_object_new(defragmented_url, &obj);