fix error with custom agent with circular reference
This commit is contained in:
parent
bffaa2aadc
commit
524308aa61
3
index.js
3
index.js
@ -66,6 +66,9 @@ function getCacheKey(requestArguments) {
|
||||
resourceCacheKeyJson.body = getBodyCacheKeyJson(resourceCacheKeyJson.body);
|
||||
initCacheKeyJson.body = getBodyCacheKeyJson(initCacheKeyJson.body);
|
||||
|
||||
delete resourceCacheKeyJson.agent;
|
||||
delete initCacheKeyJson.agent;
|
||||
|
||||
return md5(JSON.stringify([resourceCacheKeyJson, initCacheKeyJson, CACHE_VERSION]));
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ const path = require('path');
|
||||
const { URLSearchParams } = require('url');
|
||||
const standardFetch = require('node-fetch');
|
||||
const FetchCache = require('../index.js');
|
||||
const { Agent } = require('http');
|
||||
|
||||
const CACHE_PATH = path.join(__dirname, '..', '.cache');
|
||||
const expectedPngBuffer = fs.readFileSync(path.join(__dirname, 'expected_png.png'));
|
||||
@ -299,6 +300,13 @@ describe('Cache tests', function() {
|
||||
res = await cachedFetch(TWO_HUNDRED_URL, post(data2));
|
||||
assert.strictEqual(res.fromCache, true);
|
||||
});
|
||||
|
||||
it('Does not error with custom agent with circular properties', async function() {
|
||||
const agent = new Agent();
|
||||
agent.agent = agent;
|
||||
|
||||
await cachedFetch('http://httpbin.org/status/200', { agent });
|
||||
})
|
||||
}).timeout(10000);
|
||||
|
||||
describe('Data tests', function() {
|
||||
|
Reference in New Issue
Block a user