web_api: Fix caching of https.agent objects between requests
This commit is contained in:
parent
41ea9ee15b
commit
3917ab940e
2 changed files with 7 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"serverUrl": "https://textsecure-service-staging.whispersystems.org",
|
||||
"cdnUrl": "https://cdn-staging.signal.org",
|
||||
"contentProxyUrl": "contentproxy.signal.org",
|
||||
"contentProxyUrl": "http://contentproxy.signal.org:443",
|
||||
"disableAutoUpdate": false,
|
||||
"openDevTools": false,
|
||||
"buildExpiration": 0,
|
||||
|
|
|
@ -186,25 +186,27 @@ function _promiseAjax(providedUrl, options) {
|
|||
`${options.type} ${url}${options.unauthenticated ? ' (unauth)' : ''}`
|
||||
);
|
||||
}
|
||||
|
||||
const timeout =
|
||||
typeof options.timeout !== 'undefined' ? options.timeout : 10000;
|
||||
|
||||
const { proxyUrl } = options;
|
||||
const agentType = options.unauthenticated ? 'unauth' : 'auth';
|
||||
const cacheKey = `${proxyUrl}-${agentType}`;
|
||||
|
||||
const { timestamp } = agents[agentType] || {};
|
||||
const { timestamp } = agents[cacheKey] || {};
|
||||
if (!timestamp || timestamp + FIVE_MINUTES < Date.now()) {
|
||||
if (timestamp) {
|
||||
log.info(`Cycling agent for type ${agentType}`);
|
||||
log.info(`Cycling agent for type ${cacheKey}`);
|
||||
}
|
||||
agents[agentType] = {
|
||||
agents[cacheKey] = {
|
||||
agent: proxyUrl
|
||||
? new ProxyAgent(proxyUrl)
|
||||
: new Agent({ keepAlive: true }),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
const { agent } = agents[agentType];
|
||||
const { agent } = agents[cacheKey];
|
||||
|
||||
const fetchOptions = {
|
||||
method: options.type,
|
||||
|
|
Loading…
Add table
Reference in a new issue