feat: download certificate

This commit is contained in:
avwo
2020-12-18 19:16:08 +08:00
parent 6c447f034b
commit dd7ff1fe5b
2 changed files with 16 additions and 14 deletions
+9 -2
View File
@@ -27,6 +27,7 @@ var customCertsInfo = {};
var customCertsFiles = {};
var customCertCount = 0;
var cachePairs = new LRU({max: 5120});
var certsCache = new LRU({max: 256});
var ILEGAL_CHAR_RE = /[^a-z\d-]/i;
var RANDOM_SERIAL = '.' + Date.now() + '.' + Math.floor(Math.random() * 10000);
var PORT_RE = /:\d*$/;
@@ -112,7 +113,7 @@ exports.hasCustomCerts = function() {
};
function getCertificate(hostname) {
return customPairs[hostname] || cachePairs.get(hostname);
return customPairs[hostname] || cachePairs.get(hostname) || certsCache.get(hostname);
}
function _createCertificate(hostname) {
@@ -159,7 +160,13 @@ function createCertificate(hostname) {
}
exports.createCertificate = function(hostname) {
return getCertificate(hostname) || _createCertificate(hostname);
hostname = getDomain(hostname);
var cert = getCertificate(hostname);
if (!cert) {
cert = _createCertificate(hostname);
certsCache.set(hostname, cert);
}
return cert;
};
function loadCustomCerts(certDir) {