Add HTTP headers in code server to not cache content

This commit is contained in:
Alexey Andreev 2020-01-23 18:59:05 +03:00
parent 72275a0877
commit 05ac4b62bf

View File

@ -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");
}
}