diff --git a/lib/response/headers.js b/lib/response/headers.js index 5e3c29d1a..af5ce346b 100755 --- a/lib/response/headers.js +++ b/lib/response/headers.js @@ -26,7 +26,8 @@ exports.cache = function (response, request) { // Set header if (ttl) { - response.header('Cache-Control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate'); + var privacy = request._route.cache.rule.privacy; + response.header('Cache-Control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate' + (privacy !== 'default' ? ', ' + privacy : '')); } else { response.header('Cache-Control', 'no-cache'); diff --git a/lib/route.js b/lib/route.js index 32bde63e1..bc69e14f2 100755 --- a/lib/route.js +++ b/lib/route.js @@ -84,7 +84,9 @@ exports = module.exports = internals.Route = function (options, server) { // Cache Utils.assert(!this.config.cache || this.config.cache.mode === 'none' || this.method === 'get', 'Only GET routes can use a cache'); - if (this.config.cache) { + if (this.config.cache && + this.config.cache.mode !== 'none') { + this.config.cache.segment = this.config.cache.segment || this.fingerprint; } this.cache = new Catbox.Policy(this.config.cache, this.server.cache); diff --git a/test/integration/cache.js b/test/integration/cache.js index dcb44d77a..8c485be5c 100755 --- a/test/integration/cache.js +++ b/test/integration/cache.js @@ -73,7 +73,7 @@ describe('Cache', function () { _server = new Hapi.Server('0.0.0.0', 0, { cache: { engine: 'memory' } }); _server.addRoutes([ - { method: 'GET', path: '/profile', config: { handler: profileHandler, cache: { mode: 'client', expiresIn: 120000 } } }, + { method: 'GET', path: '/profile', config: { handler: profileHandler, cache: { mode: 'client', expiresIn: 120000, privacy: 'private' } } }, { method: 'GET', path: '/item', config: { handler: activeItemHandler, cache: { mode: 'client', expiresIn: 120000 } } }, { method: 'GET', path: '/item2', config: { handler: activeItemHandler, cache: { mode: 'none' } } }, { method: 'GET', path: '/item3', config: { handler: activeItemHandler, cache: { mode: 'client', expiresIn: 120000 } } }, @@ -122,7 +122,7 @@ describe('Cache', function () { makeRequest('/profile', function (rawRes) { var headers = parseHeaders(rawRes.raw.res); - expect(headers['Cache-Control']).to.equal('max-age=120, must-revalidate'); + expect(headers['Cache-Control']).to.equal('max-age=120, must-revalidate, private'); done(); }); }); @@ -132,7 +132,7 @@ describe('Cache', function () { makeRequest('/profile', function (rawRes) { var headers = parseHeaders(rawRes.raw.res); - expect(headers['Cache-Control']).to.equal('max-age=120, must-revalidate'); + expect(headers['Cache-Control']).to.equal('max-age=120, must-revalidate, private'); done(); }); });