diff --git a/config.fullstack.test.yaml b/config.fullstack.test.yaml index 465fc1bd..7fae49d6 100644 --- a/config.fullstack.test.yaml +++ b/config.fullstack.test.yaml @@ -198,6 +198,10 @@ spec_root: &spec_root # Some more general RESTBase info x-request-filters: - path: lib/security_response_header_filter.js + - path: lib/purge_content.js + options: + start_time: 1638217479863 # start of purge Unix timestamp + end_time: 1638218479863 # end of purge Unix timestamp x-sub-request-filters: - type: default diff --git a/lib/purge_content.js b/lib/purge_content.js new file mode 100644 index 00000000..e596eefd --- /dev/null +++ b/lib/purge_content.js @@ -0,0 +1,27 @@ +'use strict'; + +const mwUtil = require('./mwUtil'); + +module.exports = (hyper, req, next, options) => { + const startTime = Date.parse(options.start_time); + const endTime = Date.parse(options.end_time); + + return next(hyper, req) + .then((res) => { + if (!startTime || !endTime) { + return res; + } + + const contentTimestamp = mwUtil.extractDateFromEtag(res.headers.etag); + if (!contentTimestamp || contentTimestamp < startTime || contentTimestamp > endTime) { + return res; + } + + if (mwUtil.isNoCacheRequest(req)) { + return res; + } + + req.headers['cache-control'] = 'no-cache'; + return next(hyper, req); + }); +};