fix
This commit is contained in:
parent
e15c773b2c
commit
372a7eca7a
|
@ -32,15 +32,23 @@ export class DownloadService {
|
||||||
) {
|
) {
|
||||||
this.logger = this.loggerService.getLogger('download');
|
this.logger = this.loggerService.getLogger('download');
|
||||||
|
|
||||||
this.undiciFetcher = new UndiciFetcher(this.httpRequestService.getStandardUndiciFetcherConstructorOption({
|
this.undiciFetcher = new UndiciFetcher(this.httpRequestService.getStandardUndiciFetcherConstructorOption(
|
||||||
connect: this.httpRequestService.getConnectorWithIpCheck(
|
{
|
||||||
buildConnector({
|
connect: process.env.NODE_ENV === 'development' ?
|
||||||
...this.httpRequestService.clientDefaults.connect,
|
this.httpRequestService.clientDefaults.connect
|
||||||
}),
|
:
|
||||||
(ip) => !this.isPrivateIp(ip)
|
this.httpRequestService.getConnectorWithIpCheck(
|
||||||
),
|
buildConnector({
|
||||||
bodyTimeout: 30 * 1000,
|
...this.httpRequestService.clientDefaults.connect,
|
||||||
}));
|
}),
|
||||||
|
(ip) => !this.isPrivateIp(ip)
|
||||||
|
),
|
||||||
|
bodyTimeout: 30 * 1000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connect: this.httpRequestService.clientDefaults.connect,
|
||||||
|
}
|
||||||
|
), this.logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -88,7 +96,7 @@ export class DownloadService {
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private isPrivateIp(ip: string): boolean {
|
private isPrivateIp(ip: string): boolean {
|
||||||
for (const net of this.config.allowedPrivateNetworks ?? []) {
|
for (const net of this.config.allowedPrivateNetworks ?? []) {
|
||||||
|
|
|
@ -272,7 +272,7 @@ export class HttpRequestService {
|
||||||
* @param bypassProxy Allways bypass proxy
|
* @param bypassProxy Allways bypass proxy
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public getStandardUndiciFetcherConstructorOption(opts: undici.Agent.Options = {}) {
|
public getStandardUndiciFetcherConstructorOption(opts: undici.Agent.Options = {}, proxyOpts: undici.Agent.Options = {}) {
|
||||||
return {
|
return {
|
||||||
agentOptions: {
|
agentOptions: {
|
||||||
...this.clientDefaults,
|
...this.clientDefaults,
|
||||||
|
@ -283,6 +283,7 @@ export class HttpRequestService {
|
||||||
uri: this.config.proxy,
|
uri: this.config.proxy,
|
||||||
options: {
|
options: {
|
||||||
connections: this.maxSockets,
|
connections: this.maxSockets,
|
||||||
|
...proxyOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} : {}),
|
} : {}),
|
||||||
|
@ -310,7 +311,7 @@ export class HttpRequestService {
|
||||||
public getConnectorWithIpCheck(connector: undici.buildConnector.connector, checkIp: IpChecker): undici.buildConnector.connectorAsync {
|
public getConnectorWithIpCheck(connector: undici.buildConnector.connector, checkIp: IpChecker): undici.buildConnector.connectorAsync {
|
||||||
return (options, cb) => {
|
return (options, cb) => {
|
||||||
connector(options, (err, socket) => {
|
connector(options, (err, socket) => {
|
||||||
this.logger.debug('Socket connector called', socket);
|
this.logger.debug('Socket connector (with ip checker) called', socket);
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.error(`Socket error`, err)
|
this.logger.error(`Socket error`, err)
|
||||||
cb(new Error(`Error while socket connecting\n${err}`), null);
|
cb(new Error(`Error while socket connecting\n${err}`), null);
|
||||||
|
|
Loading…
Reference in a new issue