From 26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Nov 2019 16:03:07 +0000 Subject: llcache: Split out scheme is cachable check. --- content/llcache.c | 65 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'content') diff --git a/content/llcache.c b/content/llcache.c index e79411279..f34286603 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -1519,6 +1519,43 @@ format_error: return res; } +/** + * 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. * @@ -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); -- cgit v1.2.3