From 372a7eca7a7e51ebdeb59eabedc5461c3f5f5314 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 3 Jan 2023 14:06:48 +0000 Subject: [PATCH] fix --- packages/backend/src/core/DownloadService.ts | 28 ++++++++++++------- .../backend/src/core/HttpRequestService.ts | 5 ++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/core/DownloadService.ts b/packages/backend/src/core/DownloadService.ts index 0185d88534..09b4d94aa9 100644 --- a/packages/backend/src/core/DownloadService.ts +++ b/packages/backend/src/core/DownloadService.ts @@ -32,15 +32,23 @@ export class DownloadService { ) { this.logger = this.loggerService.getLogger('download'); - this.undiciFetcher = new UndiciFetcher(this.httpRequestService.getStandardUndiciFetcherConstructorOption({ - connect: this.httpRequestService.getConnectorWithIpCheck( - buildConnector({ - ...this.httpRequestService.clientDefaults.connect, - }), - (ip) => !this.isPrivateIp(ip) - ), - bodyTimeout: 30 * 1000, - })); + this.undiciFetcher = new UndiciFetcher(this.httpRequestService.getStandardUndiciFetcherConstructorOption( + { + connect: process.env.NODE_ENV === 'development' ? + this.httpRequestService.clientDefaults.connect + : + this.httpRequestService.getConnectorWithIpCheck( + buildConnector({ + ...this.httpRequestService.clientDefaults.connect, + }), + (ip) => !this.isPrivateIp(ip) + ), + bodyTimeout: 30 * 1000, + }, + { + connect: this.httpRequestService.clientDefaults.connect, + } + ), this.logger); } @bindThis @@ -88,7 +96,7 @@ export class DownloadService { cleanup(); } } - + @bindThis private isPrivateIp(ip: string): boolean { for (const net of this.config.allowedPrivateNetworks ?? []) { diff --git a/packages/backend/src/core/HttpRequestService.ts b/packages/backend/src/core/HttpRequestService.ts index d3a0963ed5..f6c2034019 100644 --- a/packages/backend/src/core/HttpRequestService.ts +++ b/packages/backend/src/core/HttpRequestService.ts @@ -272,7 +272,7 @@ export class HttpRequestService { * @param bypassProxy Allways bypass proxy */ @bindThis - public getStandardUndiciFetcherConstructorOption(opts: undici.Agent.Options = {}) { + public getStandardUndiciFetcherConstructorOption(opts: undici.Agent.Options = {}, proxyOpts: undici.Agent.Options = {}) { return { agentOptions: { ...this.clientDefaults, @@ -283,6 +283,7 @@ export class HttpRequestService { uri: this.config.proxy, options: { connections: this.maxSockets, + ...proxyOpts, } } } : {}), @@ -310,7 +311,7 @@ export class HttpRequestService { public getConnectorWithIpCheck(connector: undici.buildConnector.connector, checkIp: IpChecker): undici.buildConnector.connectorAsync { return (options, cb) => { connector(options, (err, socket) => { - this.logger.debug('Socket connector called', socket); + this.logger.debug('Socket connector (with ip checker) called', socket); if (err) { this.logger.error(`Socket error`, err) cb(new Error(`Error while socket connecting\n${err}`), null);