Chore/Perf: fetch enable HTTP/2

This commit is contained in:
SukkaW
2024-10-08 19:50:31 +08:00
parent 92985a409d
commit de9429ce92
7 changed files with 31 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import process from 'node:process';
import { async as ezspawn } from '@jsdevtools/ez-spawn';
import { mkdirp } from './misc';
import { fetchWithRetry } from './fetch-retry';
const mihomoBinaryDir = path.join(__dirname, '../../node_modules/.cache/mihomo');
const mihomoBinaryPath = path.join(mihomoBinaryDir, 'mihomo');
@@ -32,7 +33,7 @@ const ensureMihomoBinary = async () => {
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`);
}
const res = await fetch(downloadUrl);
const res = await fetchWithRetry(downloadUrl);
if (!res.ok || !res.body) {
throw new Error(`Failed to download mihomo binary: ${res.statusText}`);

View File

@@ -2,6 +2,10 @@ import retry from 'async-retry';
import picocolors from 'picocolors';
import { setTimeout } from 'node:timers/promises';
import { setGlobalDispatcher, Agent } from 'undici';
setGlobalDispatcher(new Agent({ allowH2: true }));
function isClientError(err: unknown): err is NodeJS.ErrnoException {
if (!err || typeof err !== 'object') return false;