Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Expires header (max one year) for #410

  • Loading branch information...
commit e10844e75a0d6b8eb7725f5a2f80ad6b8ae3d0bb 1 parent c8ad541
@ryanrolds authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/middleware/static.js
View
11 lib/middleware/static.js
@@ -67,6 +67,12 @@ exports = module.exports = function static(root, options){
exports.mime = mime;
/**
+ * Max allowed value for Expires (RFC2616 14.21)
+ */
+
+var msInAYear = 31536000000;
+
+/**
* Attempt to tranfer the requseted file to `res`.
*
* @param {ServerRequest}
@@ -140,8 +146,13 @@ var send = exports.send = function(req, res, next, options){
return;
}
+ // date for Expires header - cant be more then a year
+ var expiresDate = (maxAge <= msInAYear) ? maxAge : msInAYear;
+ expiresDate = new Date().getTime() + expiresDate;
+
// header fields
if (!res.getHeader('Date')) res.setHeader('Date', new Date().toUTCString());
+ if (!res.getHeader('Expires')) res.setHeader('Expires', new Date(expiresDate).toUTCString());
if (!res.getHeader('Cache-Control')) res.setHeader('Cache-Control', 'public, max-age=' + (maxAge / 1000));
if (!res.getHeader('Last-Modified')) res.setHeader('Last-Modified', stat.mtime.toUTCString());
if (!res.getHeader('Content-Type')) {
Please sign in to comment.
Something went wrong with that request. Please try again.