perf: Add support for sending http requests using specific nodes

Only supported on Loon & Surge
This commit is contained in:
Peng-YM
2022-08-11 01:07:16 +08:00
parent e93332048e
commit c073870f24
5 changed files with 256 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import { getFlag } from '@/utils/geo';
import lodash from 'lodash';
import $ from '@/core/app';
import { hex_md5 } from '@/vendor/md5';
import {ProxyUtils} from '@/core/proxy-utils';
/**
The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed as follows:
@@ -631,6 +632,7 @@ function createDynamicFunction(name, script, $arguments) {
'$persistentStore',
'$httpClient',
'$notification',
'ProxyUtils',
`${script}\n return ${name}`,
)(
$arguments,
@@ -642,13 +644,15 @@ function createDynamicFunction(name, script, $arguments) {
$httpClient,
// eslint-disable-next-line no-undef
$notification,
ProxyUtils
);
} else {
return new Function(
'$arguments',
'$substore',
'lodash',
'ProxyUtils',
`${script}\n return ${name}`,
)($arguments, $, lodash);
)($arguments, $, lodash, ProxyUtils);
}
}

View File

@@ -253,6 +253,17 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
events.onRequest(method, options);
if (options.node) {
// Surge & Loon allow connecting to a server using a specified proxy node
if (isSurge) {
const build = $environment['surge-build'];
if (build && parseInt(build) >= 2407) {
options['policy-descriptor'] = options.node;
delete options.node;
}
}
}
let worker;
if (isQX) {
worker = $task.fetch({