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",
|
"serverUrl": "https://textsecure-service-staging.whispersystems.org",
|
||||||
"cdnUrl": "https://cdn-staging.signal.org",
|
"cdnUrl": "https://cdn-staging.signal.org",
|
||||||
"contentProxyUrl": "contentproxy.signal.org",
|
"contentProxyUrl": "http://contentproxy.signal.org:443",
|
||||||
"disableAutoUpdate": false,
|
"disableAutoUpdate": false,
|
||||||
"openDevTools": false,
|
"openDevTools": false,
|
||||||
"buildExpiration": 0,
|
"buildExpiration": 0,
|
||||||
|
|
|
@ -186,25 +186,27 @@ function _promiseAjax(providedUrl, options) {
|
||||||
`${options.type} ${url}${options.unauthenticated ? ' (unauth)' : ''}`
|
`${options.type} ${url}${options.unauthenticated ? ' (unauth)' : ''}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeout =
|
const timeout =
|
||||||
typeof options.timeout !== 'undefined' ? options.timeout : 10000;
|
typeof options.timeout !== 'undefined' ? options.timeout : 10000;
|
||||||
|
|
||||||
const { proxyUrl } = options;
|
const { proxyUrl } = options;
|
||||||
const agentType = options.unauthenticated ? 'unauth' : 'auth';
|
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 || timestamp + FIVE_MINUTES < Date.now()) {
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
log.info(`Cycling agent for type ${agentType}`);
|
log.info(`Cycling agent for type ${cacheKey}`);
|
||||||
}
|
}
|
||||||
agents[agentType] = {
|
agents[cacheKey] = {
|
||||||
agent: proxyUrl
|
agent: proxyUrl
|
||||||
? new ProxyAgent(proxyUrl)
|
? new ProxyAgent(proxyUrl)
|
||||||
: new Agent({ keepAlive: true }),
|
: new Agent({ keepAlive: true }),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { agent } = agents[agentType];
|
const { agent } = agents[cacheKey];
|
||||||
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: options.type,
|
method: options.type,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue