Skip to content

Commit

Permalink
Merge pull request hapijs#518 from walmartlabs/master
Browse files Browse the repository at this point in the history
Fixing master/develop mess
  • Loading branch information
Eran Hammer committed Feb 11, 2013
2 parents 5f0650f + 1c6f655 commit a78a1b1
Show file tree
Hide file tree
Showing 37 changed files with 21 additions and 22 deletions.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified examples/file/index.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/_pages/.placeholder
100644 → 100755
Empty file.
Empty file modified examples/views/cms/pages.js
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/create.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/edit.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/index.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/layout.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/page.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/partials/footer.html
100644 → 100755
Empty file.
Empty file modified examples/views/cms/views/partials/nav.html
100644 → 100755
Empty file.
Empty file modified examples/views/jade/templates/about.jade
100644 → 100755
Empty file.
Empty file modified examples/views/jade/templates/includes/foot.jade
100644 → 100755
Empty file.
Empty file modified examples/views/jade/templates/includes/head.jade
100644 → 100755
Empty file.
Empty file modified examples/views/jade/templates/index.jade
100644 → 100755
Empty file.
Empty file modified examples/views/jade/templates/layout.jade
100644 → 100755
Empty file.
Empty file modified examples/views/mixed/templates/handlebars.html
100644 → 100755
Empty file.
Empty file modified examples/views/mixed/templates/index.jade
100644 → 100755
Empty file.
23 changes: 3 additions & 20 deletions lib/response/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ var Mime = require('mime');
var Err = require('../error');
var Utils = require('../utils');
var Stream = require('./stream');
var LRU = require('lru-cache');
var Crypto = require('crypto');


// Declare internals

var internals = {};
internals.fileEtags = LRU();


// File response (Base -> Generic -> Stream -> File)

Expand Down Expand Up @@ -52,23 +50,8 @@ internals.File.prototype._prepare = function (request, callback) {
Stream.call(self, stream);
self._headers['Content-Type'] = Mime.lookup(self._filePath) || 'application/octet-stream';
self._headers['Content-Length'] = stat.size;

// Use stat info for an LRU cache key.
var cachekey = [self._filePath, stat.ino, stat.size, Date.parse(stat.mtime)].join('-');

// The etag must hash the file contents in order to be consistent between nodes.
if (internals.fileEtags.has(cachekey)) {
self._headers.etag = JSON.stringify(internals.fileEtags.get(cachekey));
} else {
var hash = Crypto.createHash('md5');
stream.on('data', function (chunk) {
hash.update(chunk);
})
stream.on('end', function () {
internals.fileEtags.set(cachekey, hash.digest("hex"));
})
}

self._headers['Last-Modified'] = new Date(stat.mtime).toUTCString();
self._headers.etag = JSON.stringify([stat.ino, stat.size, Date.parse(stat.mtime)].join('-'));
self._headers['Content-Disposition'] = 'inline; filename=' + encodeURIComponent(fileName);

return Stream.prototype._prepare.call(self, request, callback);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"catbox": "0.1.x",
"cryptiles": "0.0.x",
"iron": "0.1.x",
"semver": "1.1.0",
"lru-cache": "~2.2.2"
"semver": "1.1.0"
},
"devDependencies": {
"mocha": "1.x.x",
Expand Down
Empty file modified proposals/RFC.CacheMemorySize.md
100644 → 100755
Empty file.
Empty file modified proposals/RFC.DocGeneration.md
100644 → 100755
Empty file.
Empty file modified proposals/RFC.QueryConfig.md
100644 → 100755
Empty file.
Empty file modified proposals/RFC.QueryValidation.md
100644 → 100755
Empty file.
Empty file modified proposals/RFC.Throttling.md
100644 → 100755
Empty file.
Empty file modified proposals/Routing/RFC.RouteConfig.md
100644 → 100755
Empty file.
Empty file modified proposals/Routing/new_routes.js
100644 → 100755
Empty file.
Empty file modified proposals/Routing/routes.js
100644 → 100755
Empty file.
Empty file modified test/integration/.hidden
100644 → 100755
Empty file.
Empty file modified test/integration/directory/subdir/subsubdir/placeholder
100644 → 100755
Empty file.
Empty file modified test/integration/directory/subdir/test.txt
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions test/integration/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,23 @@ describe('Response', function () {
});
});

it('returns a 304 when the request has a future modifed-since', function (done) {

server.start(function () {

var date = new Date(Date.now());
var headers = {
'if-modified-since': new Date(date.setFullYear(date.getFullYear() + 1)).toUTCString()
};

Request.get({ url: 'http://localhost:17082/file', headers: headers }, function (err, res) {

expect(res.statusCode).to.equal(304);
done();
});
});
});

it('returns a gzipped file in the response when the request accepts gzip', function (done) {

server.start(function () {
Expand Down
Empty file modified test/unit/templates/invalid/badmustache.html
100644 → 100755
Empty file.
Empty file modified test/unit/templates/valid/handler.html
100644 → 100755
Empty file.
Empty file modified test/unit/templates/valid/partials/nav.html
100644 → 100755
Empty file.
Empty file modified test/unit/templates/valid/testMulti.jade
100644 → 100755
Empty file.
Empty file modified test/unit/templates/valid/testPartials.html
100644 → 100755
Empty file.

0 comments on commit a78a1b1

Please sign in to comment.