Skip to content

Add content purge filter #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.fullstack.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 25 2024 14:55:23 GMT+0000" # end of purge (ISO 8601)

x-sub-request-filters:
- type: default
Expand Down
33 changes: 33 additions & 0 deletions lib/purge_content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'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;
}

let contentTimestamp;
try {
contentTimestamp = mwUtil.extractDateFromEtag(res.headers.etag);
} catch (error) {
return res;
}

if (!contentTimestamp || contentTimestamp < startTime || contentTimestamp > endTime) {
return res;
}

if (mwUtil.isNoCacheRequest(req)) {
return res;
}

req.headers['cache-control'] = 'no-cache';
return next(hyper, req);
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/features/pagecontent/language_variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
})
});

Expand Down