http-preconditions
v1.0.1
Published
nodejs module for evaluting conditional request
Downloads
4
Maintainers
Readme
precondition
This module provides utilites for evaluating conditional requests (as defined in RFC 7232)
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install http-preconditions
Usage
var precondition = require('http-preconditions')
new precondition(req, options)
req
req
nodejs request object
options
The precondition
constructor take an options
argument which should be any one
of the following
weak
when set to true
, enable weak etag comparison. Defaults to false
etag
String value represents the resources etag metadata.
lastModified
Resource last-modified date as http-date string
example
var precondition = require('http-preconditions')
var precondition = new precondition(req, {weak: true, etag: 'W/blahblahblah'})
precondition.condition
Returns the result of evaluating the preconditions in the request
var precondition = require('http-preconditions')
var precondition = new precondition(req, {weak: true, etag: 'W/blahblahblah'})
if (precondition.condition) {
res.status(200)
}
Precondition.isRange(req)
Returns true
if request contains an if-range
precondition header field
Precondition.isCacheRevalidation(req)
Return true
if request is a cache revalidation request
Precondition.isConditional(req)
Returns true
if request is a conditional request