From 05ac4b62bf7c6a7ac1e17b5971055b7b2dc32c45 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 23 Jan 2020 18:59:05 +0300 Subject: [PATCH] Add HTTP headers in code server to not cache content --- .../src/main/java/org/teavm/devserver/CodeServlet.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java b/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java index 6fc1a65cf..ca6b50324 100644 --- a/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java +++ b/tools/devserver/src/main/java/org/teavm/devserver/CodeServlet.java @@ -340,6 +340,7 @@ public class CodeServlet extends HttpServlet { resp.setCharacterEncoding("UTF-8"); resp.setHeader("Access-Control-Allow-Origin", "*"); resp.setContentType(chooseContentType(fileName)); + noCache(resp); resp.getOutputStream().write(fileContent); resp.getOutputStream().flush(); log.debug("File " + path + " served as generated file"); @@ -382,6 +383,7 @@ public class CodeServlet extends HttpServlet { resp.setStatus(HttpServletResponse.SC_OK); resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/javascript"); + noCache(resp); try (InputStream input = loader.getResourceAsStream("teavm/devserver/deobfuscator.js")) { IOUtils.copy(input, resp.getOutputStream()); } @@ -609,6 +611,7 @@ public class CodeServlet extends HttpServlet { resp.setStatus(HttpServletResponse.SC_OK); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); + noCache(resp); IOUtils.copy(stream, resp.getOutputStream()); resp.getOutputStream().flush(); return true; @@ -1090,4 +1093,8 @@ public class CodeServlet extends HttpServlet { } return path; } + + static void noCache(HttpServletResponse response) { + response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + } }