Skip to content

Commit

Permalink
closes #373
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jan 26, 2013
1 parent 5b3bc7c commit 7c60ddb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/response/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } },
Expand Down Expand Up @@ -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();
});
});
Expand All @@ -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();
});
});
Expand Down

0 comments on commit 7c60ddb

Please sign in to comment.