mirror of
https://github.com/misskey-dev/media-proxy.git
synced 2025-04-29 02:47:26 +09:00
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import * as http from 'node:http';
|
|
import * as https from 'node:https';
|
|
import CacheableLookup from 'cacheable-lookup';
|
|
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
|
|
const cache = new CacheableLookup({
|
|
maxTtl: 3600, // 1hours
|
|
errorTtl: 30, // 30secs
|
|
lookup: false, // nativeのdns.lookupにfallbackしない
|
|
});
|
|
const _http = new http.Agent({
|
|
keepAlive: true,
|
|
keepAliveMsecs: 30 * 1000,
|
|
lookup: cache.lookup,
|
|
});
|
|
const _https = new https.Agent({
|
|
keepAlive: true,
|
|
keepAliveMsecs: 30 * 1000,
|
|
lookup: cache.lookup,
|
|
});
|
|
export function getAgents(proxy) {
|
|
const httpAgent = proxy
|
|
? new HttpProxyAgent({
|
|
keepAlive: true,
|
|
keepAliveMsecs: 30 * 1000,
|
|
maxSockets: 256,
|
|
maxFreeSockets: 256,
|
|
scheduling: 'lifo',
|
|
proxy: proxy,
|
|
})
|
|
: _http;
|
|
const httpsAgent = proxy
|
|
? new HttpsProxyAgent({
|
|
keepAlive: true,
|
|
keepAliveMsecs: 30 * 1000,
|
|
maxSockets: 256,
|
|
maxFreeSockets: 256,
|
|
scheduling: 'lifo',
|
|
proxy: proxy,
|
|
})
|
|
: _https;
|
|
return {
|
|
httpAgent,
|
|
httpsAgent,
|
|
};
|
|
}
|