Provide a way to support Cache-Control: no-cache or other custom caching informations. Here's a patch:
--- lib/node-static.js.orig 2014-03-04 14:13:43.000000000 +0900
+++ lib/node-static.js 2014-03-04 14:33:00.000000000 +0900
@@ -15,16 +15,26 @@
this.root = path.resolve(root || '.');
this.options = options || {};
- this.cache = 3600;
+ this.cache = 'max-age=3600';
this.defaultHeaders = {};
this.options.headers = this.options.headers || {};
if ('cache' in this.options) {
if (typeof(this.options.cache) === 'number') {
+ if (this.options.cache > 0) {
+ this.cache = 'max-age=' + this.options.cache;
+ } else if (this.options.cache <= 0) {
+ this.cache = 'no-cache';
+ }
+ } else if (typeof(this.options.cache) === 'boolean') {
+ if (! this.options.cache) {
+ this.cache = 'no-cache';
+ }
+ } else if (this.options.cache.toLowerCase() == 'false') {
+ this.cache = 'no-cache';
+ } else if (this.options.cache.toLowerCase() != 'true') {
this.cache = this.options.cache;
- } else if (! this.options.cache) {
- this.cache = false;
}
}
@@ -36,9 +46,7 @@
this.defaultHeaders['server'] = this.serverInfo;
- if (this.cache !== false) {
- this.defaultHeaders['cache-control'] = 'max-age=' + this.cache;
- }
+ this.defaultHeaders['Cache-Control'] = this.cache;
for (var k in this.defaultHeaders) {
this.options.headers[k] = this.options.headers[k] ||
Basically this is what it produces:
.../static --cache=no-cache produces Cache-Control: no-cache
.../static --cache produces Cache-Control: max-age=3600
.../static --cache=-1 produces Cache-Control: no-cache
.../static --cache=true produces Cache-Control: max-age=3600
.../static --cache=false produces Cache-Control: no-cache
.../static --cache=1234 produces Cache-Control: max-age=1234
.../static --cache=foo-and-bar produces Cache-Control: foo-and-bar
Provide a way to support
Cache-Control: no-cacheor other custom caching informations. Here's a patch:Basically this is what it produces:
.../static --cache=no-cacheproducesCache-Control: no-cache.../static --cacheproducesCache-Control: max-age=3600.../static --cache=-1producesCache-Control: no-cache.../static --cache=trueproducesCache-Control: max-age=3600.../static --cache=falseproducesCache-Control: no-cache.../static --cache=1234producesCache-Control: max-age=1234.../static --cache=foo-and-barproducesCache-Control: foo-and-bar