Unify sendResponse in named maps controller

This commit is contained in:
Raul Ochoa 2015-07-14 17:34:05 +02:00
parent 8e8f618a22
commit 7247b20686

View File

@ -27,6 +27,13 @@ NamedMapsController.prototype.register = function(app) {
);
};
NamedMapsController.prototype.sendResponse = function(req, res, resource, headers, namedMapProvider) {
this.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(req.context.user, namedMapProvider.getTemplateName()));
res.setHeader('Content-Type', headers['Content-Type']);
res.setHeader('Cache-Control', 'public,max-age=7200,must-revalidate');
this.app.sendResponse(res, [resource, 200]);
};
NamedMapsController.prototype.tile = function(req, res) {
var self = this;
@ -60,10 +67,7 @@ NamedMapsController.prototype.tile = function(req, res) {
}
self.app.sendError(res, err, self.app.findStatusCode(err), 'NAMED_MAP_TILE', err);
} else {
self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbUser, namedMapProvider.getTemplateName()));
res.setHeader('Content-Type', headers['Content-Type']);
res.setHeader('Cache-Control', 'public,max-age=7200,must-revalidate');
self.app.sendResponse(res, [tile, headers, 200]);
self.sendResponse(req, res, tile, headers, namedMapProvider);
}
}
);
@ -158,10 +162,7 @@ NamedMapsController.prototype.staticMap = function(req, res) {
}
self.app.sendError(res, err, self.app.findStatusCode(err), 'STATIC_VIZ_MAP', err);
} else {
self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbUser, namedMapProvider.getTemplateName()));
res.setHeader('Content-Type', headers['Content-Type'] || 'image/' + format);
res.setHeader('Cache-Control', 'public,max-age=7200,must-revalidate');
self.app.sendResponse(res, [image, 200]);
self.sendResponse(req, res, image, headers, namedMapProvider);
}
}
);