Merge pull request #3 from vegar/master

Include request body as string in hash
This commit is contained in:
Randall 2020-11-27 18:47:17 -07:00 committed by GitHub
commit 5b692cef4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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