mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 02:28:23 +08:00
feat(core): unify proxy; optimize request-wrapper (#11472)
* feat(core): unify proxy; optimize request-wrapper Signed-off-by: Rongrong <i@rong.moe> * Fix DeepScan issue Signed-off-by: Rongrong <i@rong.moe> * Simplify protocol existence judgment Signed-off-by: Rongrong <i@rong.moe> * chore: regenerate yarn.lock Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const config = require('@/config').value;
|
||||
const { proxyUri, proxyUrlHandler } = require('./unify-proxy');
|
||||
let puppeteer = require('puppeteer');
|
||||
const proxyChain = require('proxy-chain');
|
||||
const logger = require('./logger');
|
||||
@@ -9,13 +10,6 @@ const options = {
|
||||
ignoreHTTPSErrors: true,
|
||||
};
|
||||
|
||||
let proxyUri;
|
||||
if (config.proxyUri && typeof config.proxyUri === 'string') {
|
||||
proxyUri = config.proxyUri;
|
||||
} else if (config.proxy && config.proxy.protocol && config.proxy.host && config.proxy.port) {
|
||||
proxyUri = `${config.proxy.protocol}://${config.proxy.host}:${config.proxy.port}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} extraOptions
|
||||
* @param {boolean} extraOptions.stealth - Use puppeteer-extra-plugin-stealth
|
||||
@@ -51,9 +45,9 @@ module.exports = async (extraOptions = {}) => {
|
||||
}
|
||||
let browser;
|
||||
if (proxyUri) {
|
||||
if (proxyUri.includes('@')) {
|
||||
if (proxyUrlHandler.username || proxyUrlHandler.password) {
|
||||
// only proxies with authentication need to be anonymized
|
||||
if (proxyUri.startsWith('http:')) {
|
||||
if (proxyUrlHandler.protocol === 'http:') {
|
||||
options.args.push(`--proxy-server=${await proxyChain.anonymizeProxy(proxyUri)}`);
|
||||
} else {
|
||||
logger.warn('SOCKS/HTTPS proxy with authentication is not supported by puppeteer, continue without proxy');
|
||||
|
||||
Reference in New Issue
Block a user