added last-modified header to tiler

This commit is contained in:
javi
2011-10-20 18:52:11 +02:00
parent 91d3bc66c8
commit 87b04ce80a
5 changed files with 56 additions and 19 deletions
+30 -8
View File
@@ -16,7 +16,7 @@ var cached_server = new CartodbWindshaft(serverOptions);
tests["first time a tile is request should not be cached"] = function() {
assert.response(cached_server, {
url: '/tiles/test_table_2/6/31/24.png?geom_type=polygon',
url: '/tiles/test_table_3/6/31/24.png?geom_type=polygon',
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
@@ -113,23 +113,25 @@ tests["LRU tile should be removed"] = function() {
tests["cache should be invalidated"] = function() {
var url = '/tiles/test_table_2/6/29/27.png';
var cached_server2 = new CartodbWindshaft(serverOptions);
var cache = CacheValidator(global.environment.redis);
assert.response(cached_server, {
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
cache.setTimestamp('windshaft_test', 'test_table_2', (new Date().getTime()/1000.0)+100, function() {
assert.response(cached_server, {
cache.setTimestamp('cartodb_test_user_1_db', 'test_table_2', (new Date().getTime()/1000.0)+100, function() {
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
assert.ok(res.header('X-Cache-hit') === undefined);
}, function(r) {
console.log('hiy', r.header('X-Cache-hit'));
assert.ok(r.header('X-Cache-hit') === undefined);
});
});
});
@@ -138,7 +140,7 @@ tests["cache should be invalidated"] = function() {
tests["Last-Modified header should be sent"] = function() {
var cached_server2 = new CartodbWindshaft(serverOptions);
var url= '/tiles/test_table_2/6/31/24.png';
var url= '/tiles/test_table/6/31/22.png';
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
@@ -146,6 +148,26 @@ tests["Last-Modified header should be sent"] = function() {
},{
status: 200
}, function(res) {
assert.ok(res.header('Last-Modified') !== undefined);
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
assert.ok(res.header('X-Cache-hit') !== undefined);
var last_modified = res.header('Last-Modified');
assert.ok(last_modified !== undefined);
assert.response(cached_server2, {
url: url,
headers: {
host: 'vizzuality.localhost.lan',
'if-modified-since': last_modified
},
method: 'GET'
}, {
status: 304
});
});
});
}
+4 -4
View File
@@ -4,12 +4,12 @@
echo "preparing redis..."
echo "HSET rails:users:vizzuality id 1" | redis-cli -n 5
echo "HSET rails:users:vizzuality database_name windshaft" | redis-cli -n 5
echo "HSET rails:users:vizzuality database_name cartodb_test_user_1_db" | redis-cli -n 5
echo "preparing postgres..."
dropdb -Upostgres -hlocalhost whindshaft_test
createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 whindshaft_test
psql -Upostgres -hlocalhost whindshaft_test < test.sql
dropdb -Upostgres -hlocalhost cartodb_test_user_1_db
createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 cartodb_test_user_1_db
psql -Upostgres -hlocalhost cartodb_test_user_1_db < windshaft.test.sql
echo "ok, you can run test now"
+4 -2
View File
@@ -63,6 +63,7 @@ CREATE INDEX test_table_the_geom_idx ON test_table USING gist (the_geom);
CREATE INDEX test_table_the_geom_webmercator_idx ON test_table USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table TO postgres;
GRANT ALL ON TABLE test_table TO tileuser;
-- second table
CREATE TABLE test_table_2 (
@@ -105,7 +106,7 @@ ALTER TABLE ONLY test_table_2 ADD CONSTRAINT test_table_2_pkey PRIMARY KEY (cart
CREATE INDEX test_table_2_the_geom_idx ON test_table_2 USING gist (the_geom);
CREATE INDEX test_table_2_the_geom_webmercator_idx ON test_table_2 USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table_2 TO postgres;
GRANT ALL ON TABLE test_table_2 TO tileuser;
-- third table
CREATE TABLE test_table_3 (
@@ -148,4 +149,5 @@ ALTER TABLE ONLY test_table_3 ADD CONSTRAINT test_table_3_pkey PRIMARY KEY (cart
CREATE INDEX test_table_3_the_geom_idx ON test_table_3 USING gist (the_geom);
CREATE INDEX test_table_3_the_geom_webmercator_idx ON test_table_3 USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table_3 TO postgres;
GRANT ALL ON TABLE test_table_3 TO postgres;
GRANT ALL ON TABLE test_table_3 TO tileuser;