aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-11-10 19:07:12 +0100
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-02 08:02:50 +0200
commit65754053fb92b26b1df4cafd0605e6c2546f204e (patch)
treec8bc0a21b7bebddb04c360c875a93667d9b20084 /server/src
parentbf8772fba339c6a09654f1631673d3e6b1dfcbe7 (diff)
downloadvaadin-framework-65754053fb92b26b1df4cafd0605e6c2546f204e.tar.gz
vaadin-framework-65754053fb92b26b1df4cafd0605e6c2546f204e.zip
set Cache-Control and Expires header even when not-modified (#8757)
Usually first a resource is served with the lower code block. this provides cache-control, expires and last-modification headers to the browser. But when a not-modified response was served, these headers were missing. This effectively caused the caching to no longer work once the not-modified responses are sent out. Change-Id: I9b1f0cacc91734f88bb0384872da0d426d4b5fe0
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 4656f9a672..4fd1e97a40 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -704,6 +704,15 @@ public class VaadinServlet extends HttpServlet implements Constants {
return;
}
+ String cacheControl = "public, max-age=0, must-revalidate";
+ int resourceCacheTime = getCacheTime(filename);
+ if (resourceCacheTime > 0) {
+ cacheControl = "max-age=" + String.valueOf(resourceCacheTime);
+ }
+ response.setHeader("Cache-Control", cacheControl);
+ response.setDateHeader("Expires", System.currentTimeMillis()
+ + (resourceCacheTime * 1000));
+
// Find the modification timestamp
long lastModifiedTime = 0;
URLConnection connection = null;
@@ -714,6 +723,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
// are not returned by the browser in the "If-Modified-Since"
// header).
lastModifiedTime = lastModifiedTime - lastModifiedTime % 1000;
+ response.setDateHeader("Last-Modified", lastModifiedTime);
if (browserHasNewestVersion(request, lastModifiedTime)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
@@ -748,18 +758,6 @@ public class VaadinServlet extends HttpServlet implements Constants {
response.setContentType(mimetype);
}
- // Provide modification timestamp to the browser if it is known.
- if (lastModifiedTime > 0) {
- response.setDateHeader("Last-Modified", lastModifiedTime);
-
- String cacheControl = "public, max-age=0, must-revalidate";
- int resourceCacheTime = getCacheTime(filename);
- if (resourceCacheTime > 0) {
- cacheControl = "max-age=" + String.valueOf(resourceCacheTime);
- }
- response.setHeader("Cache-Control", cacheControl);
- }
-
writeStaticResourceResponse(request, response, resourceUrl);
}