diff options
Diffstat (limited to 'lib/CookieCache.jsm')
-rw-r--r-- | lib/CookieCache.jsm | 162 |
1 files changed, 81 insertions, 81 deletions
diff --git a/lib/CookieCache.jsm b/lib/CookieCache.jsm index c3badb4..e925736 100644 --- a/lib/CookieCache.jsm +++ b/lib/CookieCache.jsm @@ -2,7 +2,7 @@ ηMatrix - a browser extension to black/white list requests. Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors - Copyright (C) 2019-2020 Alessio Vanni + Copyright (C) 2019-2022 Alessio Vanni This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see {http://www.gnu.org/licenses/}. - Home: https://libregit.spks.xyz/heckyel/ematrix + Home: https://gitlab.com/vannilla/ematrix uMatrix Home: https://github.com/gorhill/uMatrix */ @@ -61,111 +61,111 @@ CookieEntry.prototype.dispose = function () { var CookieUtils = { keyFromCookie: function (cookie) { - let cb = []; - - cb[0] = cookie.secure ? 'https' : 'http'; - cb[1] = '://'; - cb[2] = cookie.domain.charAt(0) === '.' ? - cookie.domain.slice(1) : - cookie.domain; - cb[3] = cookie.path; - cb[4] = '{'; - cb[5] = cookie.session ? 'session' : 'persistent'; - cb[6] = '-cookie:'; - cb[7] = cookie.name; - cb[8] = '}'; - - return cb.join(''); + let cb = []; + + cb[0] = cookie.secure ? 'https' : 'http'; + cb[1] = '://'; + cb[2] = cookie.domain.charAt(0) === '.' ? + cookie.domain.slice(1) : + cookie.domain; + cb[3] = cookie.path; + cb[4] = '{'; + cb[5] = cookie.session ? 'session' : 'persistent'; + cb[6] = '-cookie:'; + cb[7] = cookie.name; + cb[8] = '}'; + + return cb.join(''); }, keyFromURL: function (url, type, name) { - if (typeof url !== 'object') { - throw new Error('Invalid URL parameter'); - } - - let cb = []; - - cb[0] = url.scheme; - cb[1] = '://'; - cb[2] = url.hostname; - cb[3] = url.path; - cb[4] = '{'; - cb[5] = type; - cb[6] = '-cookie:'; - cb[7] = name; - cb[8] = '}'; - - return cb.join(''); + if (typeof url !== 'object') { + throw new Error('Invalid URL parameter'); + } + + let cb = []; + + cb[0] = url.scheme; + cb[1] = '://'; + cb[2] = url.hostname; + cb[3] = url.path; + cb[4] = '{'; + cb[5] = type; + cb[6] = '-cookie:'; + cb[7] = name; + cb[8] = '}'; + + return cb.join(''); }, urlFromEntry: function (entry) { - if (!entry) { - return ''; - } + if (!entry) { + return ''; + } - return (entry.secure ? 'https://' : 'http://') - + entry.hostname - + entry.path; + return (entry.secure ? 'https://' : 'http://') + + entry.hostname + + entry.path; }, matchDomains: function (key, allHosts) { - let entry = CookieCache.get(key); + let entry = CookieCache.get(key); - if (entry === undefined) { - return false; - } + if (entry === undefined) { + return false; + } - if (allHosts.indexOf(' '+entry.hostname+' ') < 0) { - if (!entry.anySubdomain) { - return false; - } + if (allHosts.indexOf(' '+entry.hostname+' ') < 0) { + if (!entry.anySubdomain) { + return false; + } - if (allHosts.indexOf('.'+entry.hostname+' ') < 0) { - return false; - } - } + if (allHosts.indexOf('.'+entry.hostname+' ') < 0) { + return false; + } + } - return true; + return true; }, }; var CookieCache = { add: function (cookie) { - let key = CookieUtils.keyFromCookie(cookie); - let value = dict.get(key); - - if (value === undefined) { - value = junkyard.pop(); - if (value) { - value.init(cookie); - } else { - value = new CookieEntry(cookie); - } - dict.set(key, value); - } - - return value; + let key = CookieUtils.keyFromCookie(cookie); + let value = dict.get(key); + + if (value === undefined) { + value = junkyard.pop(); + if (value) { + value.init(cookie); + } else { + value = new CookieEntry(cookie); + } + dict.set(key, value); + } + + return value; }, addVector: function (vector) { - for (let i=vector.length-1; i>=0; --i) { - CookieCache.add(vector[i]); - } + for (let i=vector.length-1; i>=0; --i) { + CookieCache.add(vector[i]); + } }, remove: function (cookie) { - let value = dict.get(cookie); - if (value === undefined) { - return false; - } + let value = dict.get(cookie); + if (value === undefined) { + return false; + } - dict.delete(cookie); + dict.delete(cookie); - if (junkyard.length < 25) { - junkyard.push(value.dispose()); - } + if (junkyard.length < 25) { + junkyard.push(value.dispose()); + } - return true; + return true; }, get: function (key) { - return dict.get(key); + return dict.get(key); }, keys: function () { - return dict.keys(); + return dict.keys(); } }; |