Skip to content

Commit

Permalink
allow throwing error on max vtile size
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Aug 30, 2017
1 parent c0d85f2 commit 90aec8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var ImagePool = function(size) {
module.exports = Bridge;

function Bridge(uri, callback) {
this.BRIDGE_MAX_VTILE_BYTES_COMPRESSED = process.env.BRIDGE_MAX_VTILE_BYTES_COMPRESSED ? +process.env.BRIDGE_MAX_VTILE_BYTES_COMPRESSED : 0;
var source = this;

if (typeof uri === 'string' || (uri.protocol && !uri.xml)) {
Expand Down Expand Up @@ -290,6 +291,9 @@ Bridge.getVector = function(source, map, z, x, y, callback) {
vtile.getData({compression:'gzip'}, function(err, pbfz) {
if (err) return callback(err);
headers['Content-Encoding'] = 'gzip';
if (source.BRIDGE_MAX_VTILE_BYTES_COMPRESSED > 0 && pbfz.length > source.BRIDGE_MAX_VTILE_BYTES_COMPRESSED) {
return callback(new Error("Tile >= max allowed size"), pbfz, headers);
}
return callback(err, pbfz, headers);
});
});
Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ var rasterxml = {
});
});
});
tape('should fail when tile generated is larger than max size', function(assert) {
new Bridge({ xml:xml.a, base:path.join(__dirname,'/') }, function(err, source) {
// monkeypatch the max tile size
source.BRIDGE_MAX_VTILE_BYTES_COMPRESSED = 1;
assert.equal(source.BRIDGE_MAX_VTILE_BYTES_COMPRESSED,1);
assert.ifError(err);
assert.ok(source);
source.getTile(0,0,0, function(err, buffer, headers) {
assert.equal(err.message, 'Tile >= max allowed size');
assert.ok(source.BRIDGE_MAX_VTILE_BYTES_COMPRESSED < buffer.length);
assert.end();
});
});
});
tape('should load with callback', function(assert) {
new Bridge({ xml: xml.a, base:path.join(__dirname,'/') }, function(err, source) {
assert.ifError(err);
Expand Down

0 comments on commit 90aec8d

Please sign in to comment.