From ad27ed6926499f3381b8e7f6d80e86268919ec6c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Nov 2019 16:47:55 +0000 Subject: llcache: Avoid putting local content in the disc cache. --- content/llcache.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'content/llcache.c') diff --git a/content/llcache.c b/content/llcache.c index f34286603..ccfa61d84 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -1519,6 +1519,34 @@ format_error: return res; } +/** + * Check whether a scheme is persistable. + * + * \param url URL to check. + * \return true iff url has a persistable scheme. + */ +static inline bool llcache__scheme_is_persistable(const nsurl *url) +{ + lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME); + bool persistable = 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))) { + persistable = true; + } + + lwc_string_unref(scheme); + + return persistable; +} + /** * Check whether a scheme is cachable. * @@ -1578,6 +1606,12 @@ llcache_object_fetch_persistent(llcache_object *object, nsurl *referer_clone = NULL; llcache_post_data *post_clone = NULL; + if (!llcache__scheme_is_persistable(object->url)) { + /* Don't bother looking up non-http(s) stuff; we don't + * persist it. */ + return NSERROR_NOT_FOUND; + } + object->cache.req_time = time(NULL); object->cache.fin_time = object->cache.req_time; @@ -2494,6 +2528,11 @@ build_candidate_list(struct llcache_object ***lst_out, int *lst_len_out) for (object = llcache->cached_objects; object != NULL; object = next) { next = object->next; + /* Only consider http(s) for the disc cache. */ + if (!llcache__scheme_is_persistable(object->url)) { + continue; + } + remaining_lifetime = llcache_object_rfc2616_remaining_lifetime( &object->cache); -- cgit v1.2.3