notmodified v0.2.4
#notmodified
set and validate http cache headers
Installation
npm install notmodifiedExample
var notmodified = require('notmodified');
var http = require('http');
var startTime = new Date();
http.createServer(function (req, res) {
var valid = notmodified(req, res, {
'hash': 'string-value',
'mtime': startTime
});
if (valid) return res.end();
res.end('Big chunk of data there should be cached');
}).listen();API documentation
var notmodified = requrie('notmodified');
var valid = notmodified(req, res, cache);requrie('notmodified') returns a function where the first two arguments
are the http req and res object. The next argument (cache) is an object
containing the cache validation data.
The notmodified function returns a valid boolean. If valid is true the
client cache is valid and res.statusCode has been set to 304. However
res.end() should stil be called.
The cache object can have three optional properties:
hashthis is theETagvalue and must be a string. If its not set noETagheader will be send. If the client sends aif-none-matchbut nohashvalue is givenvalidwill befalse.mtimeis theLast-Modifiedvalue and must beDateobject. Just as with theETagthe header will only be send ifmtimeis specified andvalidwill befalseif the client sendIf-Modified-Sincebut nomtimewas set.weakthis is an extension to theETagheader and must be a boolean. If its not set it defaults tofalse. This indicated if theETagis byte-by-byte valid and if aRangerequest makes sence. Specifically if and only iftrueETagwill be prefixed withW/.
License
The software is license under "MIT"
Copyright (c) 2013 Andreas Madsen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.