Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use md5 for etag calculation. #46

Open
wants to merge 1 commit into from

1 participant

@Reregistered

...tent length. should provide more reliable etag

Dov Amihod changed the etag calculation to use md5 of the file instead of time+ …
…content length. should provide more reliable etag
36f0553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 20, 2012
  1. changed the etag calculation to use md5 of the file instead of time+ …

    Dov Amihod authored
    …content length. should provide more reliable etag
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/staticGzip.js
View
18 lib/staticGzip.js
@@ -13,6 +13,7 @@ var fs = require('fs'),
path = require('path'),
mime = require('mime'),
zlib = require('zlib'),
+ crypto = require('crypto'),
staticSend;
try {
staticSend = require('connect').static.send;
@@ -115,10 +116,10 @@ exports = module.exports = function staticGzip(dirPath, options){
res.setHeader('Content-Length', cacheObj.content.length);
res.setHeader('Last-Modified', cacheObj.mtime.toUTCString());
res.setHeader('Date', new Date().toUTCString());
- res.setHeader('Expires', new Date(Date.now() + clientMaxAge).toUTCString());
- res.setHeader('Cache-Control', 'public, max-age=' + (clientMaxAge / 1000));
- res.setHeader('ETag', '"' + cacheObj.content.length + '-' + Number(cacheObj.mtime) + '"');
- }
+ res.setHeader('Expires', new Date(Date.now() + clientMaxAge).toUTCString());
+ res.setHeader('Cache-Control', 'public, max-age=' + (clientMaxAge / 1000));
+ res.setHeader('ETag', '"' + cacheObj.etag + '"');
+ }
function sendGzipped(cacheObj) {
setHeaders(cacheObj);
@@ -127,10 +128,17 @@ exports = module.exports = function staticGzip(dirPath, options){
function gzipAndSend(filename, gzipName, mtime) {
gzippo(filename, charset, function(gzippedData) {
+
+ var etag;
+ var md5 = crypto.createHash('md5');
+ md5.update(gzippedData);
+ etag = md5.digest('base64');
+
gzippoCache[gzipName] = {
'ctime': Date.now(),
'mtime': mtime,
- 'content': gzippedData
+ 'etag' : etag,
+ 'content': gzippedData
};
sendGzipped(gzippoCache[gzipName]);
});
Something went wrong with that request. Please try again.