Compare commits

..

No commits in common. "a97b5921c91154464e79cebe4ca53c4d3e3d473e" and "a2517d3d03f068e4b8c7e94ad9bfb168fcf486b8" have entirely different histories.

View file

@ -27,11 +27,21 @@ export type HttpRequestSendOptions = {
@Injectable()
export class HttpRequestService {
/**
* Get http non-proxy agent
*/
private http: http.Agent;
/**
* Get https non-proxy agent
*/
private https: https.Agent;
/**
* Get http proxy or non-proxy agent
*/
public httpAgent: http.Agent;
/**
* Get https proxy or non-proxy agent
*/
@ -47,16 +57,34 @@ export class HttpRequestService {
lookup: false, // nativeのdns.lookupにfallbackしない
});
this.http = new http.Agent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
lookup: cache.lookup as unknown as net.LookupFunction,
localAddress: config.outgoingAddress,
});
this.https = new https.Agent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
lookup: cache.lookup as unknown as net.LookupFunction,
localAddress: config.outgoingAddress,
minVersion: 'TLSv1.2',
});
const maxSockets = Math.max(256, config.deliverJobConcurrency ?? 128);
this.httpAgent = config.proxy
? new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
maxSockets,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: config.proxy,
localAddress: config.outgoingAddress,
})
: this.http;
this.httpsAgent = config.proxy
? new HttpsProxyAgent({
keepAlive: true,
@ -76,17 +104,11 @@ export class HttpRequestService {
* @param bypassProxy Allways bypass proxy
*/
@bindThis
public getAgentByUrl(url: URL, bypassProxy = false): https.Agent {
if (url.protocol !== 'https:') {
throw new Error('Invalid protocol');
}
if (url.port && url.port !== '443') {
throw new Error('Invalid port');
}
public getAgentByUrl(url: URL, bypassProxy = false): http.Agent | https.Agent {
if (bypassProxy || (this.config.proxyBypassHosts ?? []).includes(url.hostname)) {
return this.https;
return url.protocol === 'http:' ? this.http : this.https;
} else {
return this.httpsAgent;
return url.protocol === 'http:' ? this.httpAgent : this.httpsAgent;
}
}