Skip to content

Node.js module for handling conditional requests (as defined in RFC 7232)

License

Notifications You must be signed in to change notification settings

rxbryan/precondition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM Version codecov

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

License

MIT License

Author

Bryan Elee (rxbryn@gmail.com)

About

Node.js module for handling conditional requests (as defined in RFC 7232)

Resources

License

Stars

Watchers

Forks

Packages

No packages published