Comparing version 2.1.5 to 2.1.6
@@ -101,3 +101,3 @@ // Load modules | ||
Items.serial(paths, function (path, next) { | ||
Items.serial(paths, function (path, nextPath) { | ||
@@ -119,3 +119,3 @@ path = Path.join(path, selection || ''); | ||
if (!settings.defaultExtension) { | ||
return next(); | ||
return nextPath(); | ||
} | ||
@@ -133,3 +133,3 @@ | ||
return next(); | ||
return nextPath(); | ||
}); | ||
@@ -159,3 +159,3 @@ } | ||
Items.serial(indexNames, function (indexName, next) { | ||
Items.serial(indexNames, function (indexName, nextIndex) { | ||
@@ -180,3 +180,3 @@ var indexFile = Path.join(path, indexName); | ||
return next(); | ||
return nextIndex(); | ||
}); | ||
@@ -183,0 +183,0 @@ }, |
@@ -105,5 +105,7 @@ // Load modules | ||
var hash = Crypto.createHash('sha1'); | ||
var processed = 0; | ||
response.on('peek', function (chunk) { | ||
hash.update(chunk); | ||
processed += chunk.length; | ||
}); | ||
@@ -113,4 +115,6 @@ | ||
var etag = hash.digest('hex'); | ||
etags.set(cachekey, etag); | ||
if (processed === stat.size) { | ||
var etag = hash.digest('hex'); | ||
etags.set(cachekey, etag); | ||
} | ||
}); | ||
@@ -117,0 +121,0 @@ } |
@@ -19,5 +19,5 @@ // Load modules | ||
server.decorate('reply', 'file', function (path, options) { | ||
server.decorate('reply', 'file', function (path, responseOptions) { | ||
return this.response(File.response(path, options, this.request)); | ||
return this.response(File.response(path, responseOptions, this.request)); | ||
}); | ||
@@ -24,0 +24,0 @@ |
{ | ||
"name": "inert", | ||
"description": "Static file and directory handlers plugin for hapi.js", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"repository": "git://github.com/hapijs/inert", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -354,6 +354,6 @@ // Load modules | ||
server.inject('/', function (res) { | ||
server.inject('/', function (res2) { | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.payload).to.contain('<p>test</p>'); | ||
expect(res2.statusCode).to.equal(200); | ||
expect(res2.payload).to.contain('<p>test</p>'); | ||
done(); | ||
@@ -465,5 +465,5 @@ }); | ||
server.inject('/noshowhidden/.dot/', function (res) { | ||
server.inject('/noshowhidden/.dot/', function (res2) { | ||
expect(res.statusCode).to.equal(404); | ||
expect(res2.statusCode).to.equal(404); | ||
done(); | ||
@@ -508,6 +508,6 @@ }); | ||
server.inject('/noshowhidden/.dot/', function (res) { | ||
server.inject('/noshowhidden/.dot/', function (res2) { | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.payload).to.contain('test'); | ||
expect(res2.statusCode).to.equal(200); | ||
expect(res2.payload).to.contain('test'); | ||
done(); | ||
@@ -771,3 +771,3 @@ }); | ||
expect(res.headers['content-length']).to.equal(content.length); | ||
expect(res.payload.length).to.equal(content.length); | ||
expect(res.rawPayload.length).to.equal(content.length); | ||
done(); | ||
@@ -774,0 +774,0 @@ }); |
@@ -380,7 +380,7 @@ // Load modules | ||
server.inject('/note', function (res) { | ||
server.inject('/note', function (res2) { | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.result).to.equal('Test'); | ||
expect(res.headers.etag).to.not.exist(); | ||
expect(res2.statusCode).to.equal(200); | ||
expect(res2.result).to.equal('Test'); | ||
expect(res2.headers.etag).to.not.exist(); | ||
done(); | ||
@@ -427,5 +427,5 @@ }); | ||
var fd = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd, new Buffer('Test'), 0, 4); | ||
Fs.closeSync(fd); | ||
var fd1 = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd1, new Buffer('Test'), 0, 4); | ||
Fs.closeSync(fd1); | ||
@@ -451,5 +451,5 @@ // etag after file modified, content unchanged | ||
var fd = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd, new Buffer('Test1'), 0, 5); | ||
Fs.closeSync(fd); | ||
var fd2 = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd2, new Buffer('Test1'), 0, 5); | ||
Fs.closeSync(fd2); | ||
@@ -475,5 +475,5 @@ // etag after file modified, content changed | ||
var fd = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd, new Buffer('Test'), 0, 4); | ||
Fs.closeSync(fd); | ||
var fd3 = Fs.openSync(Path.join(__dirname, 'file', 'note.txt'), 'w'); | ||
Fs.writeSync(fd3, new Buffer('Test'), 0, 4); | ||
Fs.closeSync(fd3); | ||
@@ -547,2 +547,22 @@ // No etag, content restored | ||
it('does not try to compute etag on 304 response', function (done) { | ||
var server = provisionServer(); | ||
server.route({ method: 'GET', path: '/file', handler: { file: Path.join(__dirname, '..', 'package.json') } }); | ||
var future = new Date(Date.now() + 1000); | ||
server.inject({ url: '/file', headers: { 'if-modified-since': future } }, function (res1) { | ||
expect(res1.statusCode).to.equal(304); | ||
expect(res1.headers).to.not.include('etag'); | ||
server.inject({ url: '/file', headers: { 'if-modified-since': future } }, function (res2) { | ||
expect(res2.statusCode).to.equal(304); | ||
expect(res2.headers).to.not.include('etag'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('retains etag header on head', function (done) { | ||
@@ -782,3 +802,3 @@ | ||
expect(res.headers['content-length']).to.equal(content.length); | ||
expect(res.payload.length).to.equal(content.length); | ||
expect(res.rawPayload.length).to.equal(content.length); | ||
done(); | ||
@@ -993,6 +1013,6 @@ }); | ||
var fd; | ||
var retainedFd; | ||
if (process.platform === 'win32') { | ||
// make a permissionless file by unlinking an open file | ||
fd = Fs.openSync(filename, 'r'); | ||
retainedFd = Fs.openSync(filename, 'r'); | ||
Fs.unlinkSync(filename); | ||
@@ -1031,4 +1051,4 @@ } else { | ||
// cleanup | ||
if (typeof fd === 'number') { | ||
Fs.closeSync(fd); | ||
if (typeof retainedFd === 'number') { | ||
Fs.closeSync(retainedFd); | ||
} else { | ||
@@ -1058,3 +1078,3 @@ Fs.unlinkSync(filename); | ||
expect(res.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res.payload).to.equal('\x89PNG\r'); | ||
expect(res.rawPayload).to.deep.equal(new Buffer('\x89PNG\r', 'ascii')); | ||
done(); | ||
@@ -1075,3 +1095,3 @@ }); | ||
expect(res.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res.payload).to.equal('PNG\r\n'); | ||
expect(res.rawPayload).to.deep.equal(new Buffer('PNG\r\n', 'ascii')); | ||
done(); | ||
@@ -1092,3 +1112,3 @@ }); | ||
expect(res.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res.payload).to.equal('D\xAEB\x60\x82'); | ||
expect(res.rawPayload).to.deep.equal(new Buffer('D\xAEB\x60\x82', 'ascii')); | ||
done(); | ||
@@ -1109,3 +1129,3 @@ }); | ||
expect(res.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res.payload).to.equal('D\xAEB\x60\x82'); | ||
expect(res.rawPayload).to.deep.equal(new Buffer('D\xAEB\x60\x82', 'ascii')); | ||
done(); | ||
@@ -1126,3 +1146,3 @@ }); | ||
expect(res.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res.payload).to.equal('D\xAEB\x60\x82'); | ||
expect(res.rawPayload).to.deep.equal(new Buffer('D\xAEB\x60\x82', 'ascii')); | ||
done(); | ||
@@ -1147,3 +1167,3 @@ }); | ||
expect(res2.headers['accept-ranges']).to.equal('bytes'); | ||
expect(res2.payload).to.equal('D\xAEB\x60\x82'); | ||
expect(res2.rawPayload).to.deep.equal(new Buffer('D\xAEB\x60\x82', 'ascii')); | ||
done(); | ||
@@ -1247,2 +1267,20 @@ }); | ||
}); | ||
it('never computes etags', function (done) { | ||
var server = provisionServer(); | ||
server.route({ method: 'GET', path: '/file', handler: { file: { path: Path.join(__dirname, 'file/image.png') } } }); | ||
server.inject({ url: '/file', headers: { 'range': 'bytes=0-4' } }, function (res1) { | ||
expect(res1.statusCode).to.equal(206); | ||
expect(res1.headers.etag).to.not.exist(); | ||
server.inject('/file', function (res2) { | ||
expect(res2.statusCode).to.equal(200); | ||
expect(res2.headers.etag).to.not.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -1249,0 +1287,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
368056
1852