aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2020-03-15 13:17:00 -0500
committerJesús <heckyel@hyperbola.info>2020-03-15 13:17:00 -0500
commit0abc2a48aed57ce2d50b17d3a4a3bc3eace3cf98 (patch)
tree73f94888c711a8679ecaef2a0320a80368446926
parentc6ea3c8b35e3a36be5ff5094997178e0be3b643a (diff)
downloadematrix-0abc2a48aed57ce2d50b17d3a4a3bc3eace3cf98.tar.lz
ematrix-0abc2a48aed57ce2d50b17d3a4a3bc3eace3cf98.tar.xz
ematrix-0abc2a48aed57ce2d50b17d3a4a3bc3eace3cf98.zip
Cache resolved hostnames
-rw-r--r--js/vapi-background.js8
-rw-r--r--lib/HostMap.jsm50
2 files changed, 58 insertions, 0 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js
index 061ae29..d738504 100644
--- a/js/vapi-background.js
+++ b/js/vapi-background.js
@@ -34,6 +34,7 @@
Cu.import('chrome://ematrix/content/lib/HttpRequestHeaders.jsm');
Cu.import('chrome://ematrix/content/lib/PendingRequests.jsm');
Cu.import('chrome://ematrix/content/lib/Punycode.jsm');
+ Cu.import('chrome://ematrix/content/lib/HostMap.jsm');
// Icon-related stuff
vAPI.setIcon = function (tabId, iconId, badge) {
@@ -427,6 +428,11 @@
let channelData = this.channelDataFromChannel(channel);
if (ηMatrix.userSettings.resolveCname === true) {
+ if (HostMap.get(URI.host)) {
+ this.operate(channel, HostMap.get(URI.host), topic);
+ return;
+ }
+
let CC = Components.classes;
let CI = Components.interfaces;
@@ -446,6 +452,8 @@
let uri = ios.newURI(URI.scheme+'://'+addr, null, null);
+ HostMap.put(URI.host, addr);
+
vAPI.httpObserver.operate(channel, uri, topic);
},
};
diff --git a/lib/HostMap.jsm b/lib/HostMap.jsm
new file mode 100644
index 0000000..3d6c77c
--- /dev/null
+++ b/lib/HostMap.jsm
@@ -0,0 +1,50 @@
+/*******************************************************************************
+
+ ηMatrix - a browser extension to black/white list requests.
+ Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors
+ Copyright (C) 2019 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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.org/heckyel/ematrix
+ uMatrix Home: https://github.com/gorhill/uMatrix
+*/
+
+'use strict';
+
+var EXPORTED_SYMBOLS = ['HostMap'];
+
+var map = new Map();
+
+var HostMap = {
+ put: function (key, value) {
+ if (typeof key !== 'string' || typeof value !== 'string'
+ || !key || !value) {
+ throw new Error('invalid argument(s)');
+ }
+
+ if (map.get(key)) {
+ return;
+ }
+
+ map.set(key, value);
+ },
+ get: function (key) {
+ if (typeof key !== 'string' || !key) {
+ throw new Error('invalid argument');
+ }
+
+ return map.get(key);
+ },
+};