web_api: Fix caching of https.agent objects between requests

This commit is contained in:
Scott Nonnenberg 2019-02-20 14:40:32 -08:00
parent 41ea9ee15b
commit 3917ab940e
2 changed files with 7 additions and 5 deletions

View File

@ -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,

View File

@ -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,