http-date
v1.0.3
Published
library for working with http date format
Readme
http-date
This module extends the JavaScript Date to accept valid HTTP-date
formats (as defined in RFC 7231) as constructor initializers and generate
valid IMF_fixdate HTTP-date string format for use in HTTP date header fields.
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install command:
$ npm install http-dateAccepts every valid Date constructor argument. Overrides the toString method of the
Date class, such that a call to the toString returns the preferred HTTP-date format
(as defined in RFC 7231).
The original behaviour can be obtained by calling toString with {format: 'standard'} as
arguments
console.log(new httpDate.toString({format: 'standard'}))Usage
var HttpDate = require('http-date')
httpDate = new HttpDate('Sun, 06 Nov 1994 08:49:37 GMT')Using express
var HttpDate = require('http-date')
var Stats = require('fs').Stats
lastModified = new HttpDate(req.get('if-modified-since'))
if (lastmodified.getTime() < stat.mtime.getTime())
res.sendFile(file)lastModified = new HttpDate()
res.set('Last-modified', lastModified.toString())