feat: undici 配置重定向

This commit is contained in:
xream 2025-03-15 22:50:47 +08:00
parent fc56df7bfd
commit a70dc7b913
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.18.4",
"version": "2.18.5",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {

View File

@ -360,7 +360,12 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
}
if (isNode) {
const undici = eval("require('undici')");
const { ProxyAgent, EnvHttpProxyAgent, request } = undici;
const {
ProxyAgent,
EnvHttpProxyAgent,
request,
interceptors,
} = undici;
const agentOpts = {
connect: {
rejectUnauthorized:
@ -387,12 +392,18 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
const response = await request(opts.url, {
...opts,
method: method.toUpperCase(),
dispatcher: opts.proxy
dispatcher: (opts.proxy
? new ProxyAgent({
...agentOpts,
uri: opts.proxy,
})
: new EnvHttpProxyAgent(agentOpts),
: new EnvHttpProxyAgent(agentOpts)
).compose(
interceptors.redirect({
maxRedirections: 3,
throwOnMaxRedirects: true,
}),
),
});
resolve({
statusCode: response.statusCode,