expired
Calculate when HTTP responses expire from the cache headers
![Coverage Status](https://coveralls.io/repos/github/lukechilds/expired/badge.svg?branch=master)
expired
accepts HTTP headers as an argument and will return information on when the resource will expire. Cache-Control
and Expires
headers are supported, if both exist Cache-Control
takes priority.
Install
npm install --save expired
Usage
const expired = require('expired');
const headers = {
'access-control-allow-origin': '*',
'age': '0',
'cache-control': 'public, max-age=300',
'content-encoding': 'gzip',
'content-type': 'application/json;charset=utf-8',
'date': 'Fri, 23 Dec 2016 05:50:31 GMT',
'last-modified': 'Fri, 23 Dec 2016 05:23:23 GMT',
'vary': 'Accept-Encoding, User-Agent',
'via': '1.1 varnish-v4'
};
expired(headers)
expired.in(headers)
expired.on(headers)
delay(600000).then(() => {
expired(headers)
expired.in(headers)
expired.on(headers)
});
You can also pass headers in as raw text:
const expired = require('expired');
const headers = `
Access-Control-Allow-Origin: *
Age: 0
Cache-Control: public, max-age=300
Content-Encoding: gzip
Content-Type: application/json;charset=utf-8
Date: Fri, 23 Dec 2016 05:50:31 GMT
Last-Modified: Fri, 23 Dec 2016 05:23:23 GMT
Vary: Accept-Encoding, User-Agent
Via: 1.1 varnish-v4`;
expired(headers)
API
Returns a boolean relating to whether the resource has expired or not. true
means it's expired, false
means it's fresh.
Returns the amount of milliseconds from the current date until the resource will expire. If the resource has already expired it will return a negative integer.
Returns a JavaScript Date
object for the date the resource will expire.
License
MIT © Luke Childs