Merge branch 'release/staging' into develop

This commit is contained in:
Luis Bosque 2012-09-25 17:32:03 +02:00
commit 694b425281
5 changed files with 44 additions and 16 deletions

5
NEWS.md Normal file
View File

@ -0,0 +1,5 @@
0.9.0 (25/09/12)
-----
* External resources in CartoCSS
* Added X-Cache-Channel header in all the tiler GET requests
* Small fixes

View File

@ -6,17 +6,6 @@ var _ = require('underscore')
var CartodbWindshaft = function(serverOptions) {
// set the cache chanel info to invalidate the cache on the frontend server
serverOptions.afterTileRender = function(req, res, tile, headers, callback) {
var ttl = global.environment.varnish.ttl || 86400;
Cache.generateCacheChannel(req, function(channel){
res.header('X-Cache-Channel', channel);
res.header('Last-Modified', new Date().toUTCString());
res.header('Cache-Control', 'no-cache,max-age='+ttl+',must-revalidate, public');
callback(null, tile, headers);
});
};
if(serverOptions.cache_enabled) {
console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port);
Cache.init(serverOptions.varnish_host, serverOptions.varnish_port);

View File

@ -1,6 +1,7 @@
var _ = require('underscore')
, Step = require('step')
, cartoData = require('./carto_data');
, cartoData = require('./carto_data')
, Cache = require('./cache_validator');
module.exports = function(){
var me = {
@ -17,6 +18,28 @@ module.exports = function(){
log_format: '[:date] :req[X-Real-IP] \033[90m:method\033[0m \033[36m:req[Host]:url\033[0m \033[90m:status :response-time ms -> :res[Content-Type]\033[0m'
};
// Set the cache chanel info to invalidate the cache on the frontend server
//
// @param req The request object.
// The function will have no effect unless req.res exists.
// It is expected that req.params contains 'table' and 'dbname'
//
// @param cb function(err, channel) will be called when ready.
// the channel parameter will be null if nothing was added
//
me.addCacheChannel = function(req, cb) {
// skip non-GET requests, or requests for which there's no response
if ( req.method != 'GET' || ! req.res ) { cb(null, null); return; }
var res = req.res;
var ttl = global.environment.varnish.ttl || 86400;
Cache.generateCacheChannel(req, function(channel){
res.header('X-Cache-Channel', channel);
res.header('Last-Modified', new Date().toUTCString());
res.header('Cache-Control', 'no-cache,max-age='+ttl+',must-revalidate, public');
cb(null, channel); // add last-modified too ?
});
}
/**
* Whitelist input and get database name & default geometry type from
* subdomain/user metadata held in CartoDB Redis
@ -45,6 +68,8 @@ module.exports = function(){
callback(null, xml);
}
var that = this;
Step(
function getPrivacy(){
cartoData.authorize(req, this);
@ -66,10 +91,14 @@ module.exports = function(){
cartoData.getGeometryType(req, this);
},
function finishSetup(err, data){
if ( err ) { callback(err, req); return; }
if (!_.isNull(data))
_.extend(req.params, {geom_type: data});
callback(err, req);
that.addCacheChannel(req, function(err, chan) {
callback(err, req);
});
}
);
};

View File

@ -23,7 +23,7 @@
"node-varnish": "0.1.1",
"underscore" : "1.1.x",
"grainstore" : "~0.6.2",
"windshaft" : "~0.4.14",
"windshaft" : "~0.4.16",
"step": "0.0.x",
"generic-pool": "1.0.x",
"redis": "0.7.2",

View File

@ -40,6 +40,7 @@ suite('server', function() {
method: 'GET'
},{
status: 200,
headers: { 'X-Cache-Channel': 'cartodb_test_user_1_db:my_table' },
body: '{"style":"#my_table {marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}"}'
}, function() { done(); });
});
@ -55,6 +56,8 @@ suite('server', function() {
}, function(res) {
// FIXME: should be 401 Unauthorized
assert.equal(res.statusCode, 500, res.body);
assert.deepEqual(JSON.parse(res.body),
{error: 'Sorry, you are unauthorized (permission denied)'});
done();
});
});
@ -261,6 +264,7 @@ suite('server', function() {
method: 'GET'
},{
status: 200,
headers: { 'X-Cache-Channel': 'cartodb_test_user_1_db:my_tablez' },
body: '{"infowindow":null}'
}, function() { done(); });
});
@ -326,7 +330,8 @@ suite('server', function() {
method: 'GET'
},{
status: 200,
headers: { 'Content-Type': 'text/javascript; charset=utf-8; charset=utf-8' }
headers: { 'Content-Type': 'text/javascript; charset=utf-8; charset=utf-8',
'X-Cache-Channel': 'cartodb_test_user_1_db:gadm4' }
}, function() { done(); });
});
@ -391,7 +396,7 @@ suite('server', function() {
method: 'GET'
},{
status: 200,
headers: { 'Content-Type': 'image/png' }
headers: { 'Content-Type': 'image/png', 'X-Cache-Channel': 'cartodb_test_user_1_db:gadm4' }
}, function() { done(); });
});