diff --git a/config.fullstack.test.yaml b/config.fullstack.test.yaml index 1206e69a..e584b487 100644 --- a/config.fullstack.test.yaml +++ b/config.fullstack.test.yaml @@ -229,6 +229,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: "Wed Jan 24 2024 14:55:23 GMT+0000" # start of purge (ISO 8601) + end_time: "Wed Jan 26 2024 14:55:23 GMT+0000" # end of purge (ISO 8601) 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); + }); +}; diff --git a/package.json b/package.json index 364bd4a6..101988d3 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "eslint-plugin-jsdoc": "^20.4.0", "eslint-plugin-json": "^1.4.0", "js-yaml": "^3.13.1", + "jsonc-parser": "3.2.0", "mocha": "^6.2.3", "mocha-lcov-reporter": "^1.3.0", "mocha.parallel": "^0.15.6", diff --git a/test/features/pagecontent/language_variants.js b/test/features/pagecontent/language_variants.js index e27e74d9..180630c6 100644 --- a/test/features/pagecontent/language_variants.js +++ b/test/features/pagecontent/language_variants.js @@ -158,7 +158,7 @@ describe('Language variants', function() { assert.deepEqual(res.headers['content-language'], 'de'); assert.deepEqual(res.headers['x-restbase-sunset'] || null, 'true'); assert.checkString(res.headers.etag, /^"\d+\/[a-f0-9-]+"$/); - assert.deepEqual(res.body.extract, 'Das ist eine testseite'); + assert.deepEqual(res.body.extract, 'Das ist eine testseite!'); }) });