summaryrefslogtreecommitdiff
path: root/node_modules/http-basic/lib/cache-utils.js
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/http-basic/lib/cache-utils.js
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/http-basic/lib/cache-utils.js')
-rw-r--r--node_modules/http-basic/lib/cache-utils.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/node_modules/http-basic/lib/cache-utils.js b/node_modules/http-basic/lib/cache-utils.js
new file mode 100644
index 0000000..3f76b0f
--- /dev/null
+++ b/node_modules/http-basic/lib/cache-utils.js
@@ -0,0 +1,29 @@
+'use strict';
+
+exports.isMatch = function (requestHeaders, cachedResponse) {
+ if (cachedResponse.headers['vary'] && cachedResponse.requestHeaders) {
+ return cachedResponse.headers['vary'].split(',').map(function (header) { return header.trim().toLowerCase(); }).every(function (header) {
+ return requestHeaders[header] === cachedResponse.requestHeaders[header];
+ });
+ } else {
+ return true;
+ }
+};
+exports.isExpired = function (cachedResponse) {
+ var match
+ if (cachedResponse.headers['cache-control'] && (match = /^public\, *max\-age\=(\d+)$/.exec(cachedResponse.headers['cache-control']))) {
+ var time = (Date.now() - cachedResponse.requestTimestamp) / 1000;
+ if ((+match[1]) > time) {
+ return false;
+ }
+ }
+ if (cachedResponse.statusCode === 301 || cachedResponse.statusCode === 308) return false;
+ return true;
+};
+exports.canCache = function (res) {
+ if (res.headers['etag']) return true;
+ if (/^public\, *max\-age\=(\d+)$/.test(res.headers['cache-control'])) return true;
+ if (res.statusCode === 301 || res.statusCode === 308) return true;
+
+ return false;
+};