diff --git a/src/index.ts b/src/index.ts index 01194cd..4bc8530 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,7 +55,9 @@ Erii.bind( if (options.verbose) { logger.enableDebugMode(); } - if (!options.noProxy && !process.env.NO_PROXY) { + if (options.noProxy) { + ProxyAgent.disableProxy(); + } else if (!process.env.NO_PROXY) { if (process.platform === "win32") { await ProxyAgent.readWindowsSystemProxy(); } diff --git a/src/utils/agent.ts b/src/utils/agent.ts index e5496e7..a8fb56c 100644 --- a/src/utils/agent.ts +++ b/src/utils/agent.ts @@ -83,6 +83,9 @@ class ProxyAgentHelper { * Note: environment variables will override system proxy in Windows. */ readProxyConfigurationFromEnv() { + if (process.env.NO_PROXY) { + return; + } const proxySettings = process.env.ALL_PROXY || process.env.HTTP_PROXY || process.env.HTTPS_PROXY; if (proxySettings) { this.setProxy(process.env.ALL_PROXY || process.env.HTTP_PROXY || process.env.HTTPS_PROXY); @@ -113,6 +116,13 @@ class ProxyAgentHelper { // ignore } } + + /** + * Disable proxy by setting proxyAgentInstance to null + */ + disableProxy() { + this.proxyAgentInstance = null; + } } export default new ProxyAgentHelper(); diff --git a/src/utils/m3u8.ts b/src/utils/m3u8.ts index ed44066..15d1ad8 100644 --- a/src/utils/m3u8.ts +++ b/src/utils/m3u8.ts @@ -32,6 +32,7 @@ export async function loadM3U8({ path, retries = 1, timeout = 60000, initPrimary ...(!axios.defaults.headers.common["Host"] ? { Host: new URL(path).host } : {}), }, cancelToken: source.token, + proxy: proxyAgent ? undefined : false, // P3647 }); logger.info("M3U8 file fetched."); m3u8Content = response.data; diff --git a/src/utils/media.ts b/src/utils/media.ts index ebd85d0..d8d79a3 100644 --- a/src/utils/media.ts +++ b/src/utils/media.ts @@ -99,6 +99,7 @@ export function download(url: string, path: string, options: AxiosRequestConfig }, cancelToken: source.token, ...options, + proxy: proxyAgentInstance ? undefined : false, // P8f0a }); if ( response.headers["content-length"] && @@ -136,6 +137,7 @@ export async function requestRaw(url: string, options: AxiosRequestConfig = {}): Host: new URL(url).host, }, ...options, + proxy: proxyAgentInstance ? undefined : false, // P8f0a }); } /**