pass header information with a .getTile() request

This commit is contained in:
Konstantin Käfer
2011-06-28 16:47:23 +02:00
parent 413ecb3b57
commit f5c87a14fa
2 changed files with 31 additions and 4 deletions
+16 -4
View File
@@ -24,14 +24,19 @@ MBTiles.utils = require('./utils');
// - callback: Will be called when the resources have been acquired
// or acquisition failed.
function MBTiles(uri, callback) {
var mbtiles = this;
if (typeof callback !== 'function') callback = noop;
if (typeof uri === 'string') uri = url.parse(uri);
this.filename = uri.pathname;
this.db = new sqlite3.cached.Database(uri.pathname, function(err) {
this.db = new sqlite3.cached.Database(mbtiles.filename, function(err) {
if (err) return callback(err);
else callback(null, this);
}.bind(this));
else fs.stat(mbtiles.filename, function(err, stat) {
if (err) return callback(err);
mbtiles.stat = stat;
callback(null, mbtiles);
});
});
};
// Finds all mbtiles file in the filepath and returns their tilesource URI.
@@ -279,7 +284,14 @@ MBTiles.prototype.getTile = function(z, x, y, callback) {
function(err, row) {
if (!row || (err && err.errno == 1)) callback(new Error('Tile does not exist'));
else if (err) callback(err);
else callback(null, row.tile_data);
else {
var options = {
'Content-Type': MBTiles.utils.getMimeType(row.tile_data),
'Last-Modified': mbtiles.stat.mtime,
'E-Tag': mbtiles.stat.size + '-' + Number(mbtiles.stat.mtime)
};
callback(null, row.tile_data, options);
}
});
};