diff --git a/NEWS.md b/NEWS.md index 96ed3ea0..b7ec587e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ 1.10.1 -- 2014-MM-DD ------------------- +Bug fixes: + + - Do not cache non-success jsonp responses (#186) + 1.10.0 -- 2014-03-20 ------------------- diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index f3ec9587..23878a7f 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -76,9 +76,14 @@ var CartodbWindshaft = function(serverOptions) { var that = this; var thatArgs = arguments; var statusCode; - if ( args.length > 2 ) statusCode = args[2]; - else { - statusCode = args[1] || 200; + if ( res._windshaftStatusCode ) { + // Added by our override of sendError + statusCode = res._windshaftStatusCode; + } else { + if ( args.length > 2 ) statusCode = args[2]; + else { + statusCode = args[1] || 200; + } } var req = res.req; Step ( @@ -117,6 +122,14 @@ var CartodbWindshaft = function(serverOptions) { ); }; + var ws_sendError = ws.sendError; + ws.sendError = function() { + var res = arguments[0]; + var statusCode = arguments[2]; + res._windshaftStatusCode = statusCode; + 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 0392083a..2066d6de 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -620,6 +620,24 @@ suite('server', function() { }); }); + // See http://github.com/CartoDB/Windshaft-cartodb/issues/186 + test("get'ing the grid of a private table should fail when unauthenticated (jsonp)", + function(done) { + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/test_table_private_1/6/31/24.grid.json?callback=x', + method: 'GET' + },{}, function(res) { + // It's forbidden, but jsonp calls for status = 200 + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + // Still, we do NOT want to add caching headers here + // See https://github.com/CartoDB/Windshaft-cartodb/issues/186 + assert.ok(!res.headers.hasOwnProperty('cache-control'), + "Unexpected Cache-Control: " + res.headers['cache-control']); + done(); + }); + }); + // See http://github.com/Vizzuality/Windshaft-cartodb/issues/55 test("get'ing grid of private table should fail on unknown username", function(done) {