From b83367cbf2e0470cc1ad4eed8ec6eafaafafdbad Mon Sep 17 00:00:00 2001 From: Gauthier Date: Wed, 25 Jun 2025 16:40:24 +0200 Subject: [PATCH] fix(proxy): apply all proxy settings to Axios (#1741) --- server/api/externalapi.ts | 2 ++ server/api/tautulli.ts | 2 ++ server/lib/imageproxy.ts | 2 ++ server/utils/customProxyAgent.ts | 22 +++++++++++++--------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/api/externalapi.ts b/server/api/externalapi.ts index 82e107182..fe6ff48fa 100644 --- a/server/api/externalapi.ts +++ b/server/api/externalapi.ts @@ -37,6 +37,8 @@ class ExternalAPI { ...options.headers, }, }); + this.axios.interceptors.request = axios.interceptors.request; + this.axios.interceptors.response = axios.interceptors.response; if (options.rateLimit) { this.axios = rateLimit(this.axios, { diff --git a/server/api/tautulli.ts b/server/api/tautulli.ts index 0e5e07071..2d9340076 100644 --- a/server/api/tautulli.ts +++ b/server/api/tautulli.ts @@ -123,6 +123,8 @@ class TautulliAPI { }${settings.urlBase ?? ''}`, params: { apikey: settings.apiKey }, }); + this.axios.interceptors.request = axios.interceptors.request; + this.axios.interceptors.response = axios.interceptors.response; } public async getInfo(): Promise { diff --git a/server/lib/imageproxy.ts b/server/lib/imageproxy.ts index 5fe45a152..a7070ea81 100644 --- a/server/lib/imageproxy.ts +++ b/server/lib/imageproxy.ts @@ -150,6 +150,8 @@ class ImageProxy { baseURL: baseUrl, headers: options.headers, }); + this.axios.interceptors.request = axios.interceptors.request; + this.axios.interceptors.response = axios.interceptors.response; if (options.rateLimitOptions) { this.axios = rateLimit(this.axios, options.rateLimitOptions); diff --git a/server/utils/customProxyAgent.ts b/server/utils/customProxyAgent.ts index 309181501..c678d4b90 100644 --- a/server/utils/customProxyAgent.ts +++ b/server/utils/customProxyAgent.ts @@ -56,12 +56,9 @@ export default async function createCustomProxyAgent( : undefined; try { - const proxyUrl = - (proxySettings.useSsl ? 'https://' : 'http://') + - proxySettings.hostname + - ':' + - proxySettings.port; - + const proxyUrl = `${proxySettings.useSsl ? 'https' : 'http'}://${ + proxySettings.hostname + }:${proxySettings.port}`; const proxyAgent = new ProxyAgent({ uri: proxyUrl, token, @@ -70,10 +67,17 @@ export default async function createCustomProxyAgent( setGlobalDispatcher(proxyAgent.compose(noProxyInterceptor)); - axios.defaults.httpAgent = new HttpProxyAgent(proxyUrl); - axios.defaults.httpsAgent = new HttpsProxyAgent(proxyUrl); + axios.defaults.httpAgent = new HttpProxyAgent(proxyUrl, { + headers: token ? { 'proxy-authorization': token } : undefined, + }); + axios.defaults.httpsAgent = new HttpsProxyAgent(proxyUrl, { + headers: token ? { 'proxy-authorization': token } : undefined, + }); axios.interceptors.request.use((config) => { - if (config.url && skipUrl(config.url)) { + const url = config.baseURL + ? new URL(config.baseURL + (config.url || '')) + : config.url; + if (url && skipUrl(url)) { config.httpAgent = false; config.httpsAgent = false; }