diff --git a/lib/mbtiles.js b/lib/mbtiles.js index 2b1c4cd..2ace481 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -174,7 +174,7 @@ MBTiles.prototype.getTile = function(z, x, y, callback) { } else { var options = { 'Content-Type': MBTiles.utils.getMimeType(row.tile_data), - 'Last-Modified': mbtiles._stat.mtime, + 'Last-Modified': new Date(mbtiles._stat.mtime).toUTCString(), 'ETag': mbtiles._stat.size + '-' + Number(mbtiles._stat.mtime) }; return callback(null, row.tile_data, options); @@ -229,8 +229,12 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) { } catch (err) { return callback(new Error('Grid is invalid')); } - - callback(null, result); + var options = { + 'Content-Type': 'text/javascript', + 'Last-Modified': new Date(that._stat.mtime).toUTCString(), + 'ETag': that._stat.size + '-' + Number(that._stat.mtime) + }; + callback(null, result, options); } ); }; diff --git a/package.json b/package.json index 435fd32..3cde336 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mbtiles", - "version": "0.1.17", + "version": "0.1.18", "description": "Utilities and tilelive integration for the MBTiles format.", "url": "http://github.com/mapbox/node-mbtiles", "author": { diff --git a/test/read.test.js b/test/read.test.js index 3ecddc0..ec57212 100644 --- a/test/read.test.js +++ b/test/read.test.js @@ -37,9 +37,12 @@ exports['get tiles'] = function(beforeExit) { if (coords) { // Flip Y coordinate because file names are TMS, but .getTile() expects XYZ. coords[2] = Math.pow(2, coords[3]) - 1 - coords[2]; - mbtiles.getTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, tile) { + mbtiles.getTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, tile, headers) { if (err) throw err; assert.deepEqual(tile, fs.readFileSync(__dirname + '/fixtures/images/' + file)); + assert.equal(headers['Content-Type'], 'image/png'); + assert.ok(!isNaN(Date.parse(headers['Last-Modified']))); + assert.ok(/\d+-\d+/.test(headers['ETag'])); status.success++; }); } @@ -74,9 +77,12 @@ exports['get grids'] = function(beforeExit) { if (coords) { // Flip Y coordinate because file names are TMS, but .getTile() expects XYZ. coords[2] = Math.pow(2, coords[3]) - 1 - coords[2]; - mbtiles.getGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, grid) { + mbtiles.getGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, grid, headers) { if (err) throw err; assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8')); + assert.equal(headers['Content-Type'], 'text/javascript'); + assert.ok(!isNaN(Date.parse(headers['Last-Modified']))); + assert.ok(/\d+-\d+/.test(headers['ETag'])); status.success++; }); }