From 4d040801f484d33b7c308b821ec310838dd2800a Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 13 Jan 2014 11:20:02 +0100 Subject: [PATCH] Drop cache headers from error responses. Closes #107 (github), JIRA CDB-1423 #resolve NOTE: does not choke on headers cleanup when response headers are not set, but raises a WARNING instead (JIRA CDB-1438 #resolve) --- NEWS.md | 7 +++++++ lib/cartodb/cartodb_windshaft.js | 14 ++++++++++++++ test/acceptance/server.js | 17 +++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index fca1fbfc..d4052fd8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +1.5.3 -- 2014-01-DD +------------------- + +Bug fixes: + +* Drop cache headers from error responses (#107) + 1.5.2 -- 2013-12-05 ------------------- diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index b436194a..5b251331 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -34,6 +34,20 @@ var CartodbWindshaft = function(serverOptions) { return version; } + // Override sendError to drop added cache headers (if any) + // See http://github.com/CartoDB/Windshaft-cartodb/issues/107 + var ws_sendError = ws.sendError; + ws.sendError = function(res) { + if ( res._headers ) { + delete res._headers['cache-control']; + delete res._headers['last-modified']; + delete res._headers['x-cache-channel']; + } else { + console.log("WARNING: response has no _headers: "); console.dir(res); + } + ws_sendError.apply(this, arguments); + }; + /** * Helper to allow access to the layer to be used in the maps infowindow popup. */ diff --git a/test/acceptance/server.js b/test/acceptance/server.js index 33248fb5..b143880b 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -125,6 +125,7 @@ suite('server', function() { assert.equal(res.statusCode, 400, res.body); assert.deepEqual(JSON.parse(res.body), {error: 'Sorry, you are unauthorized (permission denied)'}); + assert.ok(!res.headers.hasOwnProperty('cache-control')); done(); }); }); @@ -142,6 +143,7 @@ suite('server', function() { assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); + assert.ok(!res.headers.hasOwnProperty('cache-control')); done(); }); }); @@ -212,9 +214,12 @@ suite('server', function() { url: '/tiles/my_table/style', method: 'POST' },{ - status: 400, body: '{"error":"must send style information"}' - }, function() { done(); }); + }, function(res) { + assert.equal(res.statusCode, 400); + assert.ok(!res.headers.hasOwnProperty('cache-control')); + done(); + }); }); test("post'ing bad style returns 400 with error", function(done){ @@ -766,6 +771,8 @@ suite('server', function() { assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); + assert.ok(!res.headers.hasOwnProperty('cache-control'), + "Unexpected Cache-Control: " + res.headers['cache-control']); done(); }); }); @@ -786,6 +793,9 @@ suite('server', function() { }, function(res) { // 401 Unauthorized assert.equal(res.statusCode, 401, res.statusCode + ': ' + res.body); + // Failed in 1.6.0 of https://github.com/CartoDB/Windshaft-cartodb/issues/107 + assert.ok(!res.headers.hasOwnProperty('cache-control'), + "Unexpected Cache-Control: " + res.headers['cache-control']); done(); }); }); @@ -1179,6 +1189,7 @@ suite('server', function() { method: 'DELETE' },{}, function(res) { assert.equal(res.statusCode, 404, res.statusCode + ': ' + res.body); + assert.ok(!res.headers.hasOwnProperty('cache-control')); done(); }); }); @@ -1210,6 +1221,7 @@ suite('server', function() { },{}, function(res) { // FIXME: should be 401 instead assert.equal(res.statusCode, 500, res.statusCode + ': ' + res.body); + assert.ok(!res.headers.hasOwnProperty('cache-control')); done(); }); }); @@ -1262,6 +1274,7 @@ suite('server', function() { method: 'DELETE' },{}, function(res) { assert.equal(res.statusCode, 404, res.statusCode + ': ' + res.body); + assert.ok(!res.headers.hasOwnProperty('cache-control')); done(); }); });