diff --git a/index.js b/index.js index ce3d024..455cc85 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,9 @@ Vector.prototype.getTile = function(z, x, y, callback) { .digest('hex')); headers['Last-Modified'] = new Date(head && head['Last-Modified'] || 0).toUTCString(); + // Passthrough backend expires header if present. + if (head['Expires']||head['expires']) headers['Expires'] = head['Expires']||head['expires']; + // Return headers for 'headers' format. if (format === 'headers') return callback(null, headers, headers); diff --git a/test/fixtures/expires.xml b/test/fixtures/expires.xml new file mode 100644 index 0000000..e8877c3 --- /dev/null +++ b/test/fixtures/expires.xml @@ -0,0 +1,30 @@ + + + + + + -180,-85.0511,180,85.0511 + 0,0,2 + png8:m=h + 0 + 8 + 1 + test:///expires + + coastline + ScaleRank + + + + + + + coastline + + + diff --git a/test/test.js b/test/test.js index b9ab5c2..7d9f831 100644 --- a/test/test.js +++ b/test/test.js @@ -16,7 +16,8 @@ var xml = { b: fs.readFileSync(path.resolve(__dirname + '/fixtures/b.xml'), 'utf8'), c: fs.readFileSync(path.resolve(__dirname + '/fixtures/c.xml'), 'utf8'), i: fs.readFileSync(path.resolve(__dirname + '/fixtures/i.xml'), 'utf8'), - space: fs.readFileSync(path.resolve(__dirname + '/fixtures/s p a c e/i.xml'), 'utf8') + space: fs.readFileSync(path.resolve(__dirname + '/fixtures/s p a c e/i.xml'), 'utf8'), + expires: fs.readFileSync(path.resolve(__dirname + '/fixtures/expires.xml'), 'utf8') }; test('should fail without backend', function(t) { @@ -88,6 +89,17 @@ test('should use fallback backend', function(t) { t.end(); }); }); +test('passes through backend expires header', function(t) { + new Vector({ source:'test:///expires', xml: xml.expires }, function(err, source) { + t.ifError(err); + source.getTile(0, 0, 0, function(err, buffer, headers) { + t.ifError(err); + t.ok(buffer); + t.equal(headers.Expires, 'Wed, 01 Jan 2020 00:00:00 GMT'); + t.end(); + }); + }); +}); var sources = { a: new Vector({ backend: new Testsource('a'), xml: xml.a }), diff --git a/test/testsource.js b/test/testsource.js index 7cbddc0..b90ab7f 100644 --- a/test/testsource.js +++ b/test/testsource.js @@ -67,6 +67,23 @@ var infos = { } } ] + }, + expires: { + minzoom:0, + maxzoom:1, + vector_layers: [ + { + "id": "coastline", + "description": "", + "minzoom": 0, + "maxzoom": 22, + "fields": { + "FeatureCla": "String", + "Note": "String", + "ScaleRank": "Number" + } + } + ] } }; var tiles = { @@ -89,7 +106,12 @@ var tiles = { var key = basename.split('.').slice(0,3).join('.'); memo[key] = fs.readFileSync(path.resolve(path.join(__dirname, 'fixtures', 'gz', basename))); return memo; - }, {}) + }, {}), + expires: fs.readdirSync(path.resolve(path.join(__dirname, 'fixtures','a'))).reduce(function(memo, basename) { + var key = basename.split('.').slice(0,3).join('.'); + memo[key] = fs.readFileSync(path.resolve(path.join(__dirname, 'fixtures', 'a', basename))); + return memo; + }, {}), }; // Additional error tile fixtures. @@ -133,6 +155,9 @@ Testsource.prototype.getTile = function(z,x,y,callback) { 'Content-Type':'application/x-protobuf' }; + // Additional headers. + if (this.uri === 'expires') headers['expires'] = new Date('2020-01-01').toUTCString(); + if (!tiles[this.uri][key]) { return callback(new Error('Tile does not exist')); } else {