Skip to content

Commit

Permalink
I discovered a bug in my code writing the test. I had the comparison …
Browse files Browse the repository at this point in the history
…backwards (>= instead of <= as it should have been) and that's why the test was failing. I'm converted to TDD.
  • Loading branch information
David Ellis committed Jul 19, 2011
1 parent e6ecba3 commit f0a8c1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/staticGzip.js
Expand Up @@ -136,10 +136,10 @@ exports = module.exports = function staticGzip(dirPath, options){
var base = path.basename(filename),
dir = path.dirname(filename),
gzipName = path.join(dir, base + '.gz');

if (req.headers['if-modified-since'] &&
gzippoCache[gzipName] &&
(new Date(gzippoCache[gzipName].mtime)).getTime() >= (new Date(req.headers['if-modified-since'])).getTime()) {
(new Date(gzippoCache[gzipName].mtime)).getTime() <= (new Date(req.headers['if-modified-since'])).getTime()) {
contentType = contentType + (charset ? '; charset=' + charset : '');
res.setHeader('Content-Type', contentType);
res.setHeader('Content-Encoding', 'gzip');
Expand Down
37 changes: 21 additions & 16 deletions test/staticGzipTest.js
Expand Up @@ -111,22 +111,27 @@ module.exports = {
);
},
'requesting gzipped utf-8 file second time caches': function() {
assert.response(app, { url: '/utf8.txt', headers: { 'Accept-Encoding':"gzip" } }, function(res) {
console.log(res);
assert.response(app,
{
url: '/utf8.txt',
headers: {
'Accept-Encoding':"gzip",
'If-Modified-Since': 'Mon, 28 Dec 2020 01:00:00 GMT'
}
},
function(res) {
console.log(res);
res.statusCode.should.equal(304);
assert.response(app,
{
url: '/utf8.txt',
headers: {
'Accept-Encoding':"gzip",
}
);

});
},
function(res) {
assert.response(app,
{
url: '/utf8.txt',
headers: {
'Accept-Encoding':"gzip",
'If-Modified-Since': 'Mon, 28 Dec 2020 01:00:00 GMT'
}
},
function(res) {
res.statusCode.should.equal(304);
}
);
}
);
}
};

0 comments on commit f0a8c1e

Please sign in to comment.