From 3917ab940eb369f70b995a94f612930634beaa39 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 20 Feb 2019 14:40:32 -0800 Subject: [PATCH] web_api: Fix caching of https.agent objects between requests --- config/default.json | 2 +- js/modules/web_api.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config/default.json b/config/default.json index fde1f3425..7ac043ab1 100644 --- a/config/default.json +++ b/config/default.json @@ -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, diff --git a/js/modules/web_api.js b/js/modules/web_api.js index 9762f9c15..c781f7987 100644 --- a/js/modules/web_api.js +++ b/js/modules/web_api.js @@ -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,