fix: add custom certificate validation to pixiv-got (#6830)

Fixes #6584
This commit is contained in:
Bao, Huang-Huang 2021-02-04 10:50:26 +08:00 committed by GitHub
parent ecba021f17
commit c8275d890d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,4 @@
const tls = require('tls');
const ipRegex = require('ip-regex');
const got = require('@/utils/got');
const logger = require('@/utils/logger');
@ -20,7 +21,7 @@ async function dohResolve(name, jsonDohEndpoint) {
return response.data.Answer.map((item) => item.data);
}
} catch (e) {
logger.error(`Failed to resolve ${pixivConfig.bypassCdnHostname}`);
logger.error(`Failed to resolve ${name}`);
logger.debug(e);
}
return [];
@ -46,11 +47,15 @@ const pixivGot = got.extend({
}
}
if (hostname) {
const actualHost = options.url.host;
options.headers = {
...options.headers,
host: options.url.host,
host: actualHost,
};
options.url.hostname = hostname;
options.checkServerIdentity = function (host, certificate) {
return tls.checkServerIdentity(actualHost, certificate);
};
}
},
],