notmodified
v0.2.4
Published
set and validate http cache headers
Downloads
11
Maintainers
Readme
#notmodified
set and validate http cache headers
Installation
npm install notmodified
Example
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:
hash
this is theETag
value and must be a string. If its not set noETag
header will be send. If the client sends aif-none-match
but nohash
value is givenvalid
will befalse
.mtime
is theLast-Modified
value and must beDate
object. Just as with theETag
the header will only be send ifmtime
is specified andvalid
will befalse
if the client sendIf-Modified-Since
but nomtime
was set.weak
this is an extension to theETag
header and must be a boolean. If its not set it defaults tofalse
. This indicated if theETag
is byte-by-byte valid and if aRange
request makes sence. Specifically if and only iftrue
ETag
will 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.