Skip to content

Commit 9d8d617

Browse files
committed
no cache override. Closes #3206
1 parent 4311884 commit 9d8d617

File tree

5 files changed

+129
-89
lines changed

5 files changed

+129
-89
lines changed

lib/defaults.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ exports.connection = {
3131
},
3232
routes: {
3333
cache: {
34-
statuses: [200, 204] // Array of HTTP status codes for which cache-control header is set
34+
statuses: [200, 204], // Array of HTTP status codes for which cache-control header is set
35+
otherwise: 'no-cache'
3536
},
3637
cors: false, // CORS headers
3738
files: {

lib/route.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ exports = module.exports = internals.Route = function (route, connection, plugin
150150
// Cache
151151

152152
if (this.method === 'get' &&
153+
typeof this.settings.cache === 'object' &&
153154
(this.settings.cache.expiresIn || this.settings.cache.expiresAt)) {
154155

155156
this.settings.cache._statuses = Hoek.mapToObject(this.settings.cache.statuses);

lib/schema.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ internals.routeBase = Joi.object({
6565
expiresIn: Joi.number(),
6666
expiresAt: Joi.string(),
6767
privacy: Joi.string().valid('default', 'public', 'private'),
68-
statuses: Joi.array().items(Joi.number().integer().min(200)).min(1)
69-
}).allow(false),
68+
statuses: Joi.array().items(Joi.number().integer().min(200)).min(1).single(),
69+
otherwise: Joi.string().required()
70+
})
71+
.allow(false),
7072
cors: Joi.object({
7173
origin: Joi.array().min(1),
7274
maxAge: Joi.number(),

lib/transmit.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,23 @@ internals.cache = function (response) {
387387

388388
const request = response.request;
389389

390-
if (response.headers['cache-control'] ||
391-
!request.route.settings.cache) {
392-
390+
if (response.headers['cache-control']) {
393391
return;
394392
}
395393

396-
const policy = request._route._cache && (request.route.settings.cache._statuses[response.statusCode] || (response.statusCode === 304 && request.route.settings.cache._statuses['200']));
394+
const policy = request.route.settings.cache &&
395+
request._route._cache &&
396+
(request.route.settings.cache._statuses[response.statusCode] || (response.statusCode === 304 && request.route.settings.cache._statuses['200']));
397+
397398
if (policy ||
398399
response.settings.ttl) {
399400

400401
const ttl = (response.settings.ttl !== null ? response.settings.ttl : request._route._cache.ttl());
401402
const privacy = (request.auth.isAuthenticated || response.headers['set-cookie'] ? 'private' : request.route.settings.cache.privacy || 'default');
402403
response._header('cache-control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate' + (privacy !== 'default' ? ', ' + privacy : ''));
403404
}
404-
else {
405-
response._header('cache-control', 'no-cache');
405+
else if (request.route.settings.cache) {
406+
response._header('cache-control', request.route.settings.cache.otherwise);
406407
}
407408
};
408409

0 commit comments

Comments
 (0)