mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-12-01 17:03:04 +00:00
feat: 更新 undici, fetch-socks; 修正 throwOnMaxRedirect; 请求参数支持传入 proxyTunnel
This commit is contained in:
7 files changed
+95
-14
No files matched your search
@@ -8,6 +8,9 @@ on:
|
||||
- master
|
||||
paths:
|
||||
- "backend/package.json"
|
||||
concurrency:
|
||||
group: build
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.36.17",
|
||||
"version": "2.36.18",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
@@ -34,7 +34,7 @@
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "^4.17.1",
|
||||
"fastestsmallesttextencoderdecoder": "^1.0.22",
|
||||
"fetch-socks": "^1.3.2",
|
||||
"fetch-socks": "^1.3.3",
|
||||
"http-proxy-middleware": "^3.0.3",
|
||||
"ip-address": "^9.0.5",
|
||||
"js-base64": "^3.7.2",
|
||||
@@ -45,7 +45,7 @@
|
||||
"ms": "^2.1.3",
|
||||
"nanoid": "^3.3.3",
|
||||
"semver": "^7.6.3",
|
||||
"undici": "^7.4.0",
|
||||
"undici": "^8.8.0",
|
||||
"yaml": "^2.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Generated
+8
-8
@@ -45,7 +45,7 @@ importers:
|
||||
specifier: ^1.0.22
|
||||
version: 1.0.22
|
||||
fetch-socks:
|
||||
specifier: ^1.3.2
|
||||
specifier: ^1.3.3
|
||||
version: 1.3.3
|
||||
http-proxy-middleware:
|
||||
specifier: ^3.0.3
|
||||
@@ -78,8 +78,8 @@ importers:
|
||||
specifier: ^7.6.3
|
||||
version: 7.8.0
|
||||
undici:
|
||||
specifier: ^7.4.0
|
||||
version: 7.25.0
|
||||
specifier: ^8.8.0
|
||||
version: 8.8.0
|
||||
yaml:
|
||||
specifier: ^2.9.0
|
||||
version: 2.9.0
|
||||
@@ -2592,9 +2592,9 @@ packages:
|
||||
undici-types@7.19.2:
|
||||
resolution: {integrity: sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==}
|
||||
|
||||
undici@7.25.0:
|
||||
resolution: {integrity: sha512-xXnp4kTyor2Zq+J1FfPI6Eq3ew5h6Vl0F/8d9XU5zZQf1tX9s2Su1/3PiMmUANFULpmksxkClamIZcaUqryHsQ==}
|
||||
engines: {node: '>=20.18.1'}
|
||||
undici@8.8.0:
|
||||
resolution: {integrity: sha512-ubshXMXwF3MQIMF1y/WxZdNBnjEKeSg2wF5mcGUtU55YTw34tnVVpKRlLf7ruDXZ5344KokPVX4RBx1wJm64Bw==}
|
||||
engines: {node: '>=22.19.0'}
|
||||
|
||||
unicode-canonical-property-names-ecmascript@2.0.1:
|
||||
resolution: {integrity: sha512-dA8WbNeb2a6oQzAQ55YlT5vQAWGV9WXOsi3SskE3bcCdM0P4SDd+24zS/OCacdRq5BkdsRj9q3Pg6YyQoxIGqg==}
|
||||
@@ -4277,7 +4277,7 @@ snapshots:
|
||||
fetch-socks@1.3.3:
|
||||
dependencies:
|
||||
socks: 2.8.9
|
||||
undici: 7.25.0
|
||||
undici: 8.8.0
|
||||
|
||||
file-entry-cache@6.0.1:
|
||||
dependencies:
|
||||
@@ -5500,7 +5500,7 @@ snapshots:
|
||||
|
||||
undici-types@7.19.2: {}
|
||||
|
||||
undici@7.25.0: {}
|
||||
undici@8.8.0: {}
|
||||
|
||||
unicode-canonical-property-names-ecmascript@2.0.1: {}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
let $;
|
||||
let openApi;
|
||||
let download;
|
||||
let downloadFile;
|
||||
let resourceCache;
|
||||
let headersResourceCache;
|
||||
let originalRead;
|
||||
@@ -49,7 +50,7 @@ describe('download github proxy regex', function () {
|
||||
({
|
||||
default: headersResourceCache,
|
||||
} = require('@/utils/headers-resource-cache'));
|
||||
({ default: download } = require('@/utils/download'));
|
||||
({ default: download, downloadFile } = require('@/utils/download'));
|
||||
ageUtils = require('@/utils/age');
|
||||
|
||||
originalRead = $.read.bind($);
|
||||
@@ -321,4 +322,43 @@ describe('download github proxy regex', function () {
|
||||
wrongPair['age-secret-key'],
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the Undici option that throws at the file redirect limit', async function () {
|
||||
const undici = eval("require('undici')");
|
||||
const originalAgent = undici.Agent;
|
||||
const originalRedirect = undici.interceptors.redirect;
|
||||
const originalRequest = undici.request;
|
||||
let redirectOptions;
|
||||
let error;
|
||||
|
||||
undici.Agent = class {
|
||||
compose() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
undici.interceptors.redirect = (options) => {
|
||||
redirectOptions = options;
|
||||
return () => {};
|
||||
};
|
||||
undici.request = async () => ({ statusCode: 500 });
|
||||
|
||||
try {
|
||||
await downloadFile(
|
||||
'https://example.com/redirecting-file',
|
||||
path.join(tempDir, 'redirecting-file'),
|
||||
);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} finally {
|
||||
undici.Agent = originalAgent;
|
||||
undici.interceptors.redirect = originalRedirect;
|
||||
undici.request = originalRequest;
|
||||
}
|
||||
|
||||
expect(error).to.be.instanceOf(Error);
|
||||
expect(redirectOptions).to.deep.equal({
|
||||
maxRedirections: 3,
|
||||
throwOnMaxRedirect: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
+36
@@ -19,8 +19,10 @@ describe('open-api HTTP adapter', function () {
|
||||
let originalEnv;
|
||||
let originalEnvHttpProxyAgent;
|
||||
let originalProxyAgent;
|
||||
let originalRedirect;
|
||||
let originalRequest;
|
||||
let agentOptions;
|
||||
let redirectOptions;
|
||||
let requestOptions;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -33,8 +35,10 @@ describe('open-api HTTP adapter', function () {
|
||||
|
||||
originalEnvHttpProxyAgent = undici.EnvHttpProxyAgent;
|
||||
originalProxyAgent = undici.ProxyAgent;
|
||||
originalRedirect = undici.interceptors.redirect;
|
||||
originalRequest = undici.request;
|
||||
agentOptions = [];
|
||||
redirectOptions = undefined;
|
||||
requestOptions = undefined;
|
||||
|
||||
class CapturingAgent {
|
||||
@@ -49,6 +53,10 @@ describe('open-api HTTP adapter', function () {
|
||||
|
||||
undici.EnvHttpProxyAgent = CapturingAgent;
|
||||
undici.ProxyAgent = CapturingAgent;
|
||||
undici.interceptors.redirect = (options) => {
|
||||
redirectOptions = options;
|
||||
return () => {};
|
||||
};
|
||||
undici.request = async (_url, options) => {
|
||||
requestOptions = options;
|
||||
return {
|
||||
@@ -65,6 +73,7 @@ describe('open-api HTTP adapter', function () {
|
||||
afterEach(function () {
|
||||
undici.EnvHttpProxyAgent = originalEnvHttpProxyAgent;
|
||||
undici.ProxyAgent = originalProxyAgent;
|
||||
undici.interceptors.redirect = originalRedirect;
|
||||
undici.request = originalRequest;
|
||||
proxyEnvKeys.forEach((key) => {
|
||||
if (originalEnv[key] == null) {
|
||||
@@ -96,6 +105,33 @@ describe('open-api HTTP adapter', function () {
|
||||
expect(agentOptions[0].requestTls.allowH2).to.equal(false);
|
||||
});
|
||||
|
||||
it('passes proxyTunnel to undici proxy agents', async function () {
|
||||
await HTTP().get({
|
||||
url: 'http://example.com/subscription',
|
||||
proxy: 'http://127.0.0.1:8080',
|
||||
proxyTunnel: true,
|
||||
});
|
||||
await HTTP().get({
|
||||
url: 'http://example.com/subscription',
|
||||
proxyTunnel: true,
|
||||
});
|
||||
|
||||
expect(agentOptions).to.have.length(2);
|
||||
expect(agentOptions.map(({ proxyTunnel }) => proxyTunnel)).to.deep.equal([
|
||||
true,
|
||||
true,
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses the Undici option that throws at the redirect limit', async function () {
|
||||
await HTTP().get('https://example.com/subscription');
|
||||
|
||||
expect(redirectOptions).to.deep.equal({
|
||||
maxRedirections: 3,
|
||||
throwOnMaxRedirect: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes Node.js request header names to lowercase', async function () {
|
||||
await HTTP({
|
||||
headers: {
|
||||
|
||||
@@ -521,7 +521,7 @@ export async function downloadFile(url, file) {
|
||||
dispatcher: new Agent().compose(
|
||||
interceptors.redirect({
|
||||
maxRedirections: 3,
|
||||
throwOnRedirect: true,
|
||||
throwOnMaxRedirect: true,
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
Vendored
+3
-1
@@ -570,12 +570,14 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
||||
...agentOpts,
|
||||
uri: opts.proxy,
|
||||
requestTls: tlsOptions,
|
||||
proxyTunnel: opts.proxyTunnel,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
dispatcher = new EnvHttpProxyAgent({
|
||||
...agentOpts,
|
||||
requestTls: tlsOptions,
|
||||
proxyTunnel: opts.proxyTunnel,
|
||||
});
|
||||
}
|
||||
const response = await request(opts.url, {
|
||||
@@ -584,7 +586,7 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
||||
dispatcher: dispatcher.compose(
|
||||
interceptors.redirect({
|
||||
maxRedirections: 3,
|
||||
throwOnMaxRedirects: true,
|
||||
throwOnMaxRedirect: true,
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user