include request body in hash

This commit is contained in:
Vegar Vikan 2020-11-28 00:01:16 +01:00
parent 01b32347a7
commit b2efd4a00c

@ -8,7 +8,12 @@ function md5(str) {
} }
async function getResponse(cacheDirPath, requestArguments, bodyFunctionName) { async function getResponse(cacheDirPath, requestArguments, bodyFunctionName) {
const cacheHash = md5(JSON.stringify(requestArguments) + bodyFunctionName); const [url, requestInit, ...rest] = requestArguments;
const requestParams = requestInit.body
? Object.assign({}, requestInit, {body: typeof requestInit.body === 'object' ? requestInit.body.toString() : requestInit.body})
: requestInit;
const cacheHash = md5(JSON.stringify([url, requestParams, ...rest]) + bodyFunctionName);
const cachedFilePath = path.join(cacheDirPath, `${cacheHash}.json`); const cachedFilePath = path.join(cacheDirPath, `${cacheHash}.json`);
try { try {