Adds layergroupid header

Closes #311
This commit is contained in:
Raul Ochoa 2015-06-18 01:13:33 +02:00
parent 5f2d5931f4
commit eaccd062d3
5 changed files with 23 additions and 8 deletions

View File

@ -319,6 +319,7 @@ NamedMapsController.prototype.instantiateTemplate = function(req, res, template_
} }
var tplhash = self.templateMaps.fingerPrint(template).substring(0,8); var tplhash = self.templateMaps.fingerPrint(template).substring(0,8);
layergroup.layergroupid = cdbuser + '@' + tplhash + '@' + layergroup.layergroupid; layergroup.layergroupid = cdbuser + '@' + tplhash + '@' + layergroup.layergroupid;
res.header('X-Layergroup-Id', layergroup.layergroupid);
self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbuser, template.name)); self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbuser, template.name));

View File

@ -362,17 +362,22 @@ module.exports = function(redisPool) {
var cacheChannel = me.buildCacheChannel(dbName, result.affectedTables); var cacheChannel = me.buildCacheChannel(dbName, result.affectedTables);
me.channelCache[cacheKey] = cacheChannel; me.channelCache[cacheKey] = cacheChannel;
if (req.res && req.method == 'GET') {
var res = req.res;
var ttl = global.environment.varnish.layergroupTtl || 86400;
res.header('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
res.header('Last-Modified', (new Date()).toUTCString());
res.header('X-Cache-Channel', cacheChannel);
}
// last update for layergroup cache buster // last update for layergroup cache buster
response.layergroupid = response.layergroupid + ':' + result.lastUpdatedTime; response.layergroupid = response.layergroupid + ':' + result.lastUpdatedTime;
response.last_updated = new Date(result.lastUpdatedTime).toISOString(); response.last_updated = new Date(result.lastUpdatedTime).toISOString();
var res = req.res;
if (res) {
if (req.method === 'GET') {
var ttl = global.environment.varnish.layergroupTtl || 86400;
res.header('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
res.header('Last-Modified', (new Date()).toUTCString());
res.header('X-Cache-Channel', cacheChannel);
}
res.header('X-Layergroup-Id', response.layergroupid);
}
return null; return null;
}, },
function finish(err) { function finish(err) {

View File

@ -69,6 +69,7 @@ suite(suiteName, function() {
assert.equal(parsedBody.last_updated, expected_last_updated); assert.equal(parsedBody.last_updated, expected_last_updated);
if ( expected_token ) { if ( expected_token ) {
assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch); assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid);
} }
else expected_token = parsedBody.layergroupid.split(':')[0]; else expected_token = parsedBody.layergroupid.split(':')[0];
next(null, res); next(null, res);
@ -1011,6 +1012,7 @@ suite(suiteName, function() {
var parsedBody = JSON.parse(res.body); var parsedBody = JSON.parse(res.body);
if ( expected_token ) { if ( expected_token ) {
assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch); assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid);
} }
else { else {
var token_components = parsedBody.layergroupid.split(':'); var token_components = parsedBody.layergroupid.split(':');
@ -1091,6 +1093,7 @@ suite(suiteName, function() {
var parsedBody = JSON.parse(res.body); var parsedBody = JSON.parse(res.body);
if ( expected_token ) { if ( expected_token ) {
assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch); assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid);
} }
else { else {
var token_components = parsedBody.layergroupid.split(':'); var token_components = parsedBody.layergroupid.split(':');

View File

@ -108,6 +108,7 @@ describe('tests from old api translated to multilayer', function() {
function(res) { function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid); assert.ok(parsed.layergroupid);
assert.equal(res.headers['x-layergroup-id'], parsed.layergroupid);
done(); done();
} }
); );
@ -128,6 +129,7 @@ describe('tests from old api translated to multilayer', function() {
function(res) { function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid); assert.ok(parsed.layergroupid);
assert.equal(res.headers['x-layergroup-id'], parsed.layergroupid);
global.environment.postgres.host = backupDBHost; global.environment.postgres.host = backupDBHost;
done(); done();
@ -150,6 +152,7 @@ describe('tests from old api translated to multilayer', function() {
function(res) { function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid); assert.ok(parsed.layergroupid);
assert.equal(res.headers['x-layergroup-id'], parsed.layergroupid);
global.environment.postgres_auth_pass = backupDBPass; global.environment.postgres_auth_pass = backupDBPass;
done(); done();
@ -246,6 +249,8 @@ describe('tests from old api translated to multilayer', function() {
assert.ok(res.headers.hasOwnProperty('x-cache-channel')); assert.ok(res.headers.hasOwnProperty('x-cache-channel'));
assert.equal(res.headers['x-cache-channel'], expectedCacheChannel); assert.equal(res.headers['x-cache-channel'], expectedCacheChannel);
assert.equal(res.headers['x-layergroup-id'], parsed.layergroupid);
done(); done();
} }
); );

View File

@ -1321,6 +1321,7 @@ describe('template_api', function() {
layergroupid = parsed.layergroupid; layergroupid = parsed.layergroupid;
assert.ok(layergroupid.match(/^localhost@/), assert.ok(layergroupid.match(/^localhost@/),
"Returned layergroupid does not start with signer name: " + layergroupid); "Returned layergroupid does not start with signer name: " + layergroupid);
assert.equal(res.headers['x-layergroup-id'], parsed.layergroupid);
assert.ok(parsed.hasOwnProperty('last_updated'), assert.ok(parsed.hasOwnProperty('last_updated'),
"Missing 'last_updated' from response body: " + res.body); "Missing 'last_updated' from response body: " + res.body);
// TODO: check value of last_updated ? // TODO: check value of last_updated ?