diff options
author | Fabian Lange <lange.fabian@gmail.com> | 2014-11-10 19:07:12 +0100 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-12-01 13:29:29 +0000 |
commit | f301dd8d759c5006cb411df0e424a876e04b84fb (patch) | |
tree | 9397ba5c592238f412b1aceba4a56878e98e8b33 /server | |
parent | 4af5c386282e476e95ae54d239a57f22ae0ba205 (diff) | |
download | vaadin-framework-f301dd8d759c5006cb411df0e424a876e04b84fb.tar.gz vaadin-framework-f301dd8d759c5006cb411df0e424a876e04b84fb.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')
-rw-r--r-- | server/src/com/vaadin/server/VaadinServlet.java | 22 |
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); } |