Don’t allow client to cache PolyGerrit index.html

The top-level index should never be cached on the client since
it’s lightweight and points to the latest versions of the gr-app
resources. This was causing issues where users were seeing stale
versions of PolyGerrit because this page was being cached.

It should be noted that the _server_ should cache the index.html
file indefinitely, and that this change introduces a potentially
confusing parameter since “cache” is used both in the context of
the in-memory cache of the binary and also the user’s browser
cache.

Bug: Issue 4403
Change-Id: I70543aceedd5eea00ba9ee5123f16aaffb1f935c
This commit is contained in:
Andrew Bonventre
2016-08-15 17:30:55 -07:00
parent 93a4c8e42d
commit a5979d5398
4 changed files with 70 additions and 8 deletions

View File

@@ -63,9 +63,21 @@ public class ResourceServletTest {
this.fs = fs;
}
private Servlet(FileSystem fs, Cache<Path, Resource> cache,
boolean refresh, boolean cacheOnClient) {
super(cache, refresh, cacheOnClient);
this.fs = fs;
}
private Servlet(FileSystem fs, Cache<Path, Resource> cache,
boolean refresh, int cacheFileSizeLimitBytes) {
super(cache, refresh, cacheFileSizeLimitBytes);
super(cache, refresh, true, cacheFileSizeLimitBytes);
this.fs = fs;
}
private Servlet(FileSystem fs, Cache<Path, Resource> cache,
boolean refresh, boolean cacheOnClient, int cacheFileSizeLimitBytes) {
super(cache, refresh, cacheOnClient, cacheFileSizeLimitBytes);
this.fs = fs;
}
@@ -155,6 +167,37 @@ public class ResourceServletTest {
assertCacheHits(cache, 2, 3);
}
@Test
public void smallFileWithoutClientCache() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, false, false);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
// Miss on getIfPresent, miss on get.
assertCacheHits(cache, 0, 2);
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
assertCacheHits(cache, 1, 2);
writeFile("/foo", "foo2");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
assertCacheHits(cache, 2, 2);
}
@Test
public void smallFileWithoutRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);