Skip to content

Commit

Permalink
Merge pull request #1318 from johngian/inject-cache-control
Browse files Browse the repository at this point in the history
pcs: Ensure cache control injection is applied
  • Loading branch information
johngian committed Mar 29, 2023
2 parents 399e648 + 80b106f commit 451a258
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.fullstack.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default_project: &default_project
mobileapps:
host: https://mobileapps.wmcloud.org
wikifeeds:
host: https://wikifeeds.wmflabs.org
host: https://wikifeeds-beta.wmflabs.org
summary:
protocol: https
implementation: mcs
Expand Down
2 changes: 1 addition & 1 deletion test/features/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Featured feed', () => {
after(() => server.stop());

function assertMCSRequest(content, date, expected) {
const serviceURI = 'https://wikifeeds.wmflabs.org';
const serviceURI = 'https://wikifeeds-beta.wmflabs.org';
let path = `/${server.config.defaultDomain}/v1/${content}`;
if (date) {
path += `/${date}`;
Expand Down
5 changes: 5 additions & 0 deletions test/features/pcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Page Content Service: /page/media-list', () => {
assert.deepEqual(/^application\/json/.test(res.headers['content-type']), true);
assert.deepEqual(!!res.body.items, true);
assert.deepEqual(!!res.headers.etag, true);
assert.deepEqual(res.headers['cache-control'], 'test_purged_cache_control');
});
});

Expand All @@ -45,6 +46,7 @@ describe('Page Content Service: /page/media-list', () => {
assert.deepEqual(res.headers['x-restbase-sunset'] || null, 'true');
assert.deepEqual(!!res.body.items, true);
assert.deepEqual(!!res.headers.etag, true);
assert.deepEqual(res.headers['cache-control'], 'test_purged_cache_control');
});
});

Expand All @@ -57,6 +59,7 @@ describe('Page Content Service: /page/media-list', () => {
assert.deepEqual(/^application\/json/.test(res.headers['content-type']), true);
assert.deepEqual(!!res.body.items, true);
assert.deepEqual(new RegExp(`^(?:W\/)?"${pageRev}\/.+"$`).test(res.headers.etag), true);
assert.deepEqual(res.headers['cache-control'], 'test_purged_cache_control');
});
});
});
Expand Down Expand Up @@ -84,6 +87,7 @@ describe('Page Content Service: /page/mobile-html', () => {
assert.deepEqual(res.status, 200);
assert.deepEqual(/^text\/html/.test(res.headers['content-type']), true);
assert.deepEqual(res.headers['x-restbase-sunset'] || null, null);
assert.deepEqual(res.headers['cache-control'], 'test_purged_cache_control');
});
});

Expand All @@ -98,6 +102,7 @@ describe('Page Content Service: /page/mobile-html', () => {
assert.deepEqual(res.status, 200);
assert.deepEqual(/^text\/html/.test(res.headers['content-type']), true);
assert.deepEqual(res.headers['x-restbase-sunset'] || null, 'true');
assert.deepEqual(res.headers['cache-control'], 'test_purged_cache_control');
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions v1/pcs/stored_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PCSEndpoint {
return this._fetchFromPCS(hyper, req)
.tap((res) => {
res.headers['x-restbase-sunset'] = true;
this._injectCacheControl.bind(this);
this._injectCacheControl.bind(this)(res);
hyper.metrics.endTiming([
'pcs_getContent_latency',
'pcs_getContent_latency_no_storage',
Expand All @@ -37,8 +37,8 @@ class PCSEndpoint {

if (mwUtils.isNoCacheRequest(req)) {
return this._fetchFromPCSAndStore(hyper, req)
.tap(() => {
this._injectCacheControl.bind(this);
.tap((res) => {
this._injectCacheControl.bind(this)(res);
hyper.metrics.endTiming([
'pcs_getContent_latency',
'pcs_getContent_latency_no_cache',
Expand All @@ -58,8 +58,8 @@ class PCSEndpoint {
return this._fetchFromPCS(hyper, req);
})
.catch({ status: 404 }, () => this._fetchFromPCSAndStore(hyper, req))
.tap(() => {
this._injectCacheControl.bind(this);
.tap((res) => {
this._injectCacheControl.bind(this)(res);
hyper.metrics.endTiming([
'pcs_getContent_latency',
'pcs_getContent_latency_cached',
Expand Down

0 comments on commit 451a258

Please sign in to comment.