mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Disable HTTP/2 support
This commit is contained in:
@@ -43,19 +43,15 @@ export const sleepWithAbort = (ms: number, signal: AbortSignal) => new Promise<v
|
|||||||
export async function fetchAssets(url: string, fallbackUrls: string[] | readonly string[]) {
|
export async function fetchAssets(url: string, fallbackUrls: string[] | readonly string[]) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
|
||||||
const fetchMainPromise = fetchWithRetry(url, { signal: controller.signal, ...defaultRequestInit })
|
|
||||||
.then(r => r.text())
|
|
||||||
.then(text => {
|
|
||||||
controller.abort();
|
|
||||||
return text;
|
|
||||||
});
|
|
||||||
const createFetchFallbackPromise = async (url: string, index: number) => {
|
const createFetchFallbackPromise = async (url: string, index: number) => {
|
||||||
|
if (index > 0) {
|
||||||
// Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL.
|
// Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL.
|
||||||
try {
|
try {
|
||||||
await sleepWithAbort(500 + (index + 1) * 10, controller.signal);
|
await sleepWithAbort(500 + (index + 1) * 10, controller.signal);
|
||||||
} catch {
|
} catch {
|
||||||
console.log(picocolors.gray('[fetch cancelled early]'), picocolors.gray(url));
|
console.log(picocolors.gray('[fetch cancelled early]'), picocolors.gray(url));
|
||||||
throw new CustomAbortError();
|
throw new CustomAbortError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (controller.signal.aborted) {
|
if (controller.signal.aborted) {
|
||||||
console.log(picocolors.gray('[fetch cancelled]'), picocolors.gray(url));
|
console.log(picocolors.gray('[fetch cancelled]'), picocolors.gray(url));
|
||||||
@@ -68,10 +64,7 @@ export async function fetchAssets(url: string, fallbackUrls: string[] | readonly
|
|||||||
};
|
};
|
||||||
|
|
||||||
return Promise.any([
|
return Promise.any([
|
||||||
fetchMainPromise,
|
createFetchFallbackPromise(url, -1),
|
||||||
...fallbackUrls.map(createFetchFallbackPromise)
|
...fallbackUrls.map(createFetchFallbackPromise)
|
||||||
]).catch(e => {
|
]);
|
||||||
console.log(`Download Rule for [${url}] failed`);
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import retry from 'async-retry';
|
|||||||
import picocolors from 'picocolors';
|
import picocolors from 'picocolors';
|
||||||
import { setTimeout } from 'node:timers/promises';
|
import { setTimeout } from 'node:timers/promises';
|
||||||
|
|
||||||
import { setGlobalDispatcher, EnvHttpProxyAgent } from 'undici';
|
|
||||||
|
|
||||||
setGlobalDispatcher(new EnvHttpProxyAgent({ allowH2: true }));
|
|
||||||
|
|
||||||
function isClientError(err: unknown): err is NodeJS.ErrnoException {
|
function isClientError(err: unknown): err is NodeJS.ErrnoException {
|
||||||
if (!err || typeof err !== 'object') return false;
|
if (!err || typeof err !== 'object') return false;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
"tar-fs": "^3.0.6",
|
"tar-fs": "^3.0.6",
|
||||||
"tldts": "^6.1.50",
|
"tldts": "^6.1.50",
|
||||||
"tldts-experimental": "^6.1.50",
|
"tldts-experimental": "^6.1.50",
|
||||||
"undici": "^6.20.0",
|
|
||||||
"wtfnode": "^0.9.3",
|
"wtfnode": "^0.9.3",
|
||||||
"yaml": "^2.5.1"
|
"yaml": "^2.5.1"
|
||||||
},
|
},
|
||||||
|
|||||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -65,9 +65,6 @@ importers:
|
|||||||
tldts-experimental:
|
tldts-experimental:
|
||||||
specifier: ^6.1.50
|
specifier: ^6.1.50
|
||||||
version: 6.1.50
|
version: 6.1.50
|
||||||
undici:
|
|
||||||
specifier: ^6.20.0
|
|
||||||
version: 6.20.0
|
|
||||||
wtfnode:
|
wtfnode:
|
||||||
specifier: ^0.9.3
|
specifier: ^0.9.3
|
||||||
version: 0.9.3
|
version: 0.9.3
|
||||||
@@ -1480,10 +1477,6 @@ packages:
|
|||||||
undici-types@5.26.5:
|
undici-types@5.26.5:
|
||||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||||
|
|
||||||
undici@6.20.0:
|
|
||||||
resolution: {integrity: sha512-AITZfPuxubm31Sx0vr8bteSalEbs9wQb/BOBi9FPlD9Qpd6HxZ4Q0+hI742jBhkPb4RT2v5MQzaW5VhRVyj+9A==}
|
|
||||||
engines: {node: '>=18.17'}
|
|
||||||
|
|
||||||
uri-js@4.4.1:
|
uri-js@4.4.1:
|
||||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||||
|
|
||||||
@@ -2978,8 +2971,6 @@ snapshots:
|
|||||||
|
|
||||||
undici-types@5.26.5: {}
|
undici-types@5.26.5: {}
|
||||||
|
|
||||||
undici@6.20.0: {}
|
|
||||||
|
|
||||||
uri-js@4.4.1:
|
uri-js@4.4.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
punycode: 2.3.1
|
punycode: 2.3.1
|
||||||
|
|||||||
Reference in New Issue
Block a user