cacheable-request
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "cacheable-request", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Wrap native HTTP requests with RFC compliant cache support", | ||
@@ -36,2 +36,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"clone-response": "^0.2.2", | ||
"get-stream": "^3.0.0", | ||
@@ -38,0 +39,0 @@ "http-cache-semantics": "^3.7.3", |
@@ -11,2 +11,3 @@ 'use strict'; | ||
const lowercaseKeys = require('lowercase-keys'); | ||
const cloneResponse = require('clone-response'); | ||
@@ -37,3 +38,3 @@ const cacheKey = opts => { | ||
const headers = revalidatedPolicy.policy.responseHeaders(); | ||
response = new Response(opts._revalidate.statusCode, headers, opts._revalidate.body, opts._revalidate.url); | ||
response = new Response(response.statusCode, headers, opts._revalidate.body, opts._revalidate.url); | ||
response.cachePolicy = revalidatedPolicy.policy; | ||
@@ -49,3 +50,5 @@ response.fromCache = true; | ||
let clonedResponse; | ||
if (cache && response.cachePolicy.storable()) { | ||
clonedResponse = cloneResponse(response); | ||
getStream.buffer(response).then(body => { | ||
@@ -55,3 +58,3 @@ const value = { | ||
url: response.url, | ||
statusCode: response.statusCode, | ||
statusCode: response.fromCache ? opts._revalidate.statusCode : response.statusCode, | ||
body | ||
@@ -62,6 +65,8 @@ }; | ||
}); | ||
} else if (opts._revalidate) { | ||
opts.cache.delete(key); | ||
} | ||
if (typeof cb === 'function') { | ||
cb(response); | ||
cb(clonedResponse || response); | ||
} | ||
@@ -68,0 +73,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7271
94
7
+ Addedclone-response@^0.2.2
+ Addedclone-response@0.2.2(transitive)
+ Addedmimic-response@1.0.1(transitive)