Set headers with set method

This commit is contained in:
Raul Ochoa
2015-09-17 02:03:09 +02:00
parent beabe48aec
commit ef86bacf7f
7 changed files with 29 additions and 28 deletions

View File

@@ -17,8 +17,8 @@ module.exports = SurrogateKeysCache;
*/
SurrogateKeysCache.prototype.tag = function(response, cacheObject) {
var newKey = cacheObject.key();
response.header('Surrogate-Key', appendSurrogateKey(
response.header('Surrogate-Key'),
response.set('Surrogate-Key', appendSurrogateKey(
response.get('Surrogate-Key'),
Array.isArray(newKey) ? cacheObject.key().join(' ') : newKey
));

View File

@@ -149,18 +149,18 @@ BaseController.prototype.req2params = function(req, callback){
};
// jshint maxcomplexity:6
BaseController.prototype.send = function(req, res, args) {
if (global.environment && global.environment.api_hostname) {
res.header('X-Served-By-Host', global.environment.api_hostname);
}
if (req.params && req.params.dbhost) {
res.header('X-Served-By-DB-Host', req.params.dbhost);
// jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) {
if (req.params.dbhost) {
res.set('X-Served-By-DB-Host', req.params.dbhost);
}
if (req.profiler) {
res.header('X-Tiler-Profiler', req.profiler.toJSONString());
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
}
if (headers) {
res.set(headers);
}
res.send.apply(res, args);
@@ -175,6 +175,7 @@ BaseController.prototype.send = function(req, res, args) {
}
}
};
// jshint maxcomplexity:6
BaseController.prototype.sendError = function(req, res, err, label) {
label = label || 'UNKNOWN';
@@ -204,7 +205,7 @@ BaseController.prototype.sendError = function(req, res, err, label) {
var errorResponseBody = { errors: [message] };
this.send(req, res, [errorResponseBody, statusCode]);
this.send(req, res, errorResponseBody, statusCode);
};
function findStatusCode(err) {

View File

@@ -221,7 +221,7 @@ LayergroupController.prototype.staticMap = function(req, res, width, height, zoo
LayergroupController.prototype.sendResponse = function(req, res, args) {
var self = this;
res.header('Cache-Control', 'public,max-age=31536000');
res.set('Cache-Control', 'public,max-age=31536000');
// Set Last-Modified header
var lastUpdated;
@@ -231,7 +231,7 @@ LayergroupController.prototype.sendResponse = function(req, res, args) {
} else {
lastUpdated = new Date();
}
res.header('Last-Modified', lastUpdated.toUTCString());
res.set('Last-Modified', lastUpdated.toUTCString());
var dbName = req.params.dbname;
step(
@@ -245,7 +245,7 @@ LayergroupController.prototype.sendResponse = function(req, res, args) {
}
if (!!affectedTables) {
var tablesCacheEntry = new TablesCacheEntry(dbName, affectedTables);
res.header('X-Cache-Channel', tablesCacheEntry.getCacheChannel());
res.set('X-Cache-Channel', tablesCacheEntry.getCacheChannel());
self.surrogateKeysCache.tag(res, tablesCacheEntry);
}
self.send(req, res, args);

View File

@@ -223,7 +223,7 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
var templateHash = self.templateMaps.fingerPrint(mapConfigProvider.template).substring(0, 8);
layergroup.layergroupid = cdbuser + '@' + templateHash + '@' + layergroup.layergroupid;
res.header('X-Layergroup-Id', layergroup.layergroupid);
res.set('X-Layergroup-Id', layergroup.layergroupid);
self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbuser, mapConfigProvider.getTemplateName()));
self.send(req, res, [layergroup, 200]);
@@ -309,9 +309,9 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
if (req.method === 'GET') {
var tableCacheEntry = new TablesCacheEntry(dbName, result.affectedTables);
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', tableCacheEntry.getCacheChannel());
res.set('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
res.set('Last-Modified', (new Date()).toUTCString());
res.set('X-Cache-Channel', tableCacheEntry.getCacheChannel());
if (result.affectedTables && result.affectedTables.length > 0) {
self.surrogateKeysCache.tag(res, tableCacheEntry);
}

View File

@@ -35,8 +35,8 @@ 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.header('Content-Type', headers['content-type'] || headers['Content-Type'] || 'image/png');
res.header('Cache-Control', 'public,max-age=7200,must-revalidate');
res.set('Content-Type', headers['content-type'] || headers['Content-Type'] || 'image/png');
res.set('Cache-Control', 'public,max-age=7200,must-revalidate');
var self = this;
@@ -52,7 +52,7 @@ NamedMapsController.prototype.sendResponse = function(req, res, resource, header
}
if (!result || !!result.affectedTables) {
// we increase cache control as we can invalidate it
res.header('Cache-Control', 'public,max-age=31536000');
res.set('Cache-Control', 'public,max-age=31536000');
var lastModifiedDate;
if (Number.isFinite(result.lastUpdatedTime)) {
@@ -60,10 +60,10 @@ NamedMapsController.prototype.sendResponse = function(req, res, resource, header
} else {
lastModifiedDate = new Date();
}
res.header('Last-Modified', lastModifiedDate.toUTCString());
res.set('Last-Modified', lastModifiedDate.toUTCString());
var tablesCacheEntry = new TablesCacheEntry(dbName, result.affectedTables);
res.header('X-Cache-Channel', tablesCacheEntry.getCacheChannel());
res.set('X-Cache-Channel', tablesCacheEntry.getCacheChannel());
if (result.affectedTables.length > 0) {
self.surrogateKeysCache.tag(res, tablesCacheEntry);
}

View File

@@ -4,8 +4,8 @@ module.exports = function cors(extraHeaders) {
if(extraHeaders) {
baseHeaders += ", " + extraHeaders;
}
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", baseHeaders);
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Headers", baseHeaders);
next();
};
};
};

View File

@@ -256,7 +256,7 @@ function bootstrap(opts) {
});
if (global.environment && global.environment.api_hostname) {
res.header('X-Served-By-Host', global.environment.api_hostname);
res.set('X-Served-By-Host', global.environment.api_hostname);
}
next();