Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(headers): make "cache-control" value configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgm committed Jan 19, 2017
1 parent 5a81ef9 commit 5ba82ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/config.js
Expand Up @@ -311,6 +311,11 @@ const conf = convict({
doc: 'Bytes of generated developer ids',
default: 16
}
},
cacheControl: {
doc: 'Hapi: a string with the value of the "Cache-Control" header when caching is disabled',
format: String,
default: 'private, no-cache, no-store, must-revalidate'
}
});

Expand Down
4 changes: 3 additions & 1 deletion lib/server/config.js
Expand Up @@ -2,11 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const config = require('../config').getProperties();

module.exports = {
connections: {
routes: {
cache: {
otherwise: 'private, no-cache, no-store, must-revalidate'
otherwise: config.cacheControl
},
cors: true,
payload: {
Expand Down
9 changes: 5 additions & 4 deletions test/lib/util.js
Expand Up @@ -3,20 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const assert = require('insist');
const config = require('../../lib/config').getProperties();

function assertSecurityHeaders(res) {
var expect = {
const expect = {
'strict-transport-security': 'max-age=15552000; includeSubDomains',
'x-content-type-options': 'nosniff',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'DENY',
'cache-control': 'private, no-cache, no-store, must-revalidate'
'x-frame-options': 'DENY'
};

Object.keys(expect).forEach(function(header) {
assert.ok(res.headers[header]);
assert.equal(res.headers[header], expect[header]);
});

assert.equal(res.headers['cache-control'], config.cacheControl);
}

module.exports = {
Expand Down

0 comments on commit 5ba82ea

Please sign in to comment.