Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dantman committed Mar 22, 2017
2 parents 9d99073 + d15d2ba commit 7f4478c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
@@ -1,5 +1,7 @@
language: node_js
node_js:
- "7"
- "6"
- "5"
- "4"
- "0.12"
Expand Down
12 changes: 9 additions & 3 deletions index.js
Expand Up @@ -16,7 +16,9 @@ var debug = require('debug')('express-cache-response-directive'),
's-maxage',
'must-revalidate',
'proxy-revalidate',
'no-transform'
'no-transform',
'stale-while-revalidate',
'stale-if-error'
],
// Directives with an optional field-name value
optionalFieldDirectives = [
Expand All @@ -26,7 +28,9 @@ var debug = require('debug')('express-cache-response-directive'),
// Directives that use a number of seconds as a value
deltaDirectives = [
'max-age',
's-maxage'
's-maxage',
'stale-while-revalidate',
'stale-if-error'
],
// Map of camel-cased option keys to the corresponding Cache-Control directives
keyMap = {
Expand All @@ -37,7 +41,9 @@ var debug = require('debug')('express-cache-response-directive'),
proxyRevalidate: 'proxy-revalidate',
maxAge: 'max-age',
sMaxage: 's-maxage',
sMaxAge: 's-maxage'
sMaxAge: 's-maxage',
staleWhileRevalidate: 'stale-while-revalidate',
staleIfError: 'stale-if-error'
},
// Default values for string patterns
patternDefaults = {
Expand Down
22 changes: 11 additions & 11 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "express-cache-response-directive",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"description": "ExpressJS middleware that gives Response objects an intuitive .cacheControl method to set Cache-Control headers.",
"keywords": [
Expand Down Expand Up @@ -28,17 +28,17 @@
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"dependencies": {
"debug": "^2.2.0",
"js-quantities": "^1.5.0"
"debug": "^2.6.3",
"js-quantities": "^1.6.6"
},
"devDependencies": {
"chai": "^3.4.1",
"coveralls": "^2.11.4",
"express": "^4.13.3",
"istanbul": "^0.4.1",
"mocha": "^2.3.4",
"mocha-jshint": "^2.2.5",
"mocha-lcov-reporter": "^1.0.0",
"supertest": "^1.1.0"
"chai": "^3.5.0",
"coveralls": "^2.12.0",
"express": "^4.15.2",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-jshint": "^2.3.1",
"mocha-lcov-reporter": "^1.3.0",
"supertest": "^3.0.0"
}
}
60 changes: 60 additions & 0 deletions test/test.js
Expand Up @@ -133,6 +133,42 @@ route('/s-maxage-3', function() {
});
});

route('/staleWhileRevalidate-1', function() {
this.cacheControl({
'stale-while-revalidate': 600
});
});

route('/staleWhileRevalidate-2', function() {
this.cacheControl({
staleWhileRevalidate: 600
});
});

route('/staleWhileRevalidate-1h', function() {
this.cacheControl({
staleWhileRevalidate: '1h'
});
});

route('/staleIfError-1', function() {
this.cacheControl({
'stale-if-error': 600
});
});

route('/staleIfError-2', function() {
this.cacheControl({
staleIfError: 600
});
});

route('/staleIfError-1h', function() {
this.cacheControl({
staleIfError: '1h'
});
});

route('/must-revalidate', function() {
this.cacheControl({
mustRevalidate: true
Expand Down Expand Up @@ -296,6 +332,30 @@ describe('res.cacheControl', function() {
requestShouldHaveCacheControl('/s-maxage-3', "s-maxage=600");
});

describe('when passed staleWhileRevalidate: 600', function() {
requestShouldHaveCacheControl('/staleWhileRevalidate-1', "stale-while-revalidate=600");
});

describe('when passed stale-while-revalidate: 600', function() {
requestShouldHaveCacheControl('/staleWhileRevalidate-2', "stale-while-revalidate=600");
});

describe('when passed stale-while-revalidate: 1h', function() {
requestShouldHaveCacheControl('/staleWhileRevalidate-1h', "stale-while-revalidate=3600");
});

describe('when passed stale-if-error: 600', function() {
requestShouldHaveCacheControl('/staleIfError-1', "stale-if-error=600");
});

describe('when passed staleIfError: 600', function() {
requestShouldHaveCacheControl('/staleIfError-2', "stale-if-error=600");
});

describe('when passed staleIfError: 1h', function() {
requestShouldHaveCacheControl('/staleIfError-1h', "stale-if-error=3600");
});

describe('when passed mustRevalidate: true', function() {
requestShouldHaveCacheControl('/must-revalidate', "must-revalidate");
});
Expand Down

0 comments on commit 7f4478c

Please sign in to comment.