Skip to content

Commit

Permalink
SAK-49840 remove old-style, redundant caching declarations (sakaiproj…
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff authored Mar 18, 2024
1 parent d82cde5 commit 3f9e265
Show file tree
Hide file tree
Showing 40 changed files with 34 additions and 171 deletions.
5 changes: 1 addition & 4 deletions admin-su/src/webapp/su/main.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
5 changes: 1 addition & 4 deletions admin-su/src/webapp/su/redirect.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
5 changes: 1 addition & 4 deletions admin-su/src/webapp/su/unauthorized.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ public void handleAccess(EntityView view, HttpServletRequest req,
// set standard no-cache headers
protected void setNoCacheHeaders(HttpServletResponse resp) {
resp.setContentType("text/html; charset=UTF-8");
// some old date
resp.addHeader("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
// TODO: do we need this? adding a date header is expensive contention
// for the date formatter, ours or Tomcats.
// resp.addDateHeader("Last-Modified", System.currentTimeMillis());
resp.addHeader("Cache-Control",
"no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
resp.addHeader("Pragma", "no-cache");
resp.addHeader("Cache-Control", "no-store");
}

private void clearSessionAttributes(Session session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,7 @@ public static void sendHTMLPage(HttpServletResponse res, String body)
{
res.setContentType("text/html; charset=UTF-8");
res.setCharacterEncoding("utf-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");
java.io.PrintWriter out = res.getWriter();

out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<%@ taglib uri="http://sakaiproject.org/jsf2/sakai" prefix="sakai"%>
<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<%@ taglib uri="http://sakaiproject.org/jsf2/sakai" prefix="sakai"%>
<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>

<f:view>
Expand Down
7 changes: 2 additions & 5 deletions chat/chat-tool/tool/src/webapp/jsp/prelude.jspf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
%>
response.addHeader("Cache-Control", "no-store");
%>
Original file line number Diff line number Diff line change
Expand Up @@ -975,13 +975,7 @@ private void handleClassLoaderAccess(EntityViewAccessProvider accessProvider,
protected void setNoCacheHeaders(HttpServletResponse res) {
long currentTime = System.currentTimeMillis();
res.setDateHeader(ActionReturn.Header.DATE.toString(), currentTime);
res.setDateHeader(ActionReturn.Header.EXPIRES.toString(), currentTime + 1000);

res.setHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "must-revalidate");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "private");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "no-store");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "max-age=0");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "s-maxage=0");
}

/**
Expand Down Expand Up @@ -1014,20 +1008,11 @@ protected void setResponseHeaders(EntityView view, HttpServletResponse res, Map<

// set the cache headers
res.setDateHeader(ActionReturn.Header.DATE.toString(), currentTime);
res.setDateHeader(ActionReturn.Header.EXPIRES.toString(), currentTime + 600000);

if (noCache) {
res.setHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "must-revalidate");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "private");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "no-store");
res.setDateHeader(ActionReturn.Header.EXPIRES.toString(), currentTime + 1000);
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "max-age=0");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "s-maxage=0");
} else {
// response.addHeader("Cache-Control", "must-revalidate");
res.setHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "public");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "max-age=600");
res.addHeader(ActionReturn.Header.CACHE_CONTROL.toString(), "s-maxage=600");
}

// set the EB specific headers
Expand Down
5 changes: 1 addition & 4 deletions help/help-tool/src/webapp/search/main.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<%@ taglib uri="http://sakaiproject.org/jsf/help" prefix="help" %>
<%
response.setContentType("text/html; charset=UTF-8");
response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
response.addDateHeader("Last-Modified", System.currentTimeMillis());
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");
%>
<f:view>
<sakai:view_container title="#{msgs.title_edit}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static void downloadSpreadsheetData(List<List<Object>> spreadsheetData, S
*/
private static void protectAgainstInstantDeletion(HttpServletResponse response) {
response.reset(); // Eliminate the added-on stuff
response.setHeader("Pragma", "public"); // Override old-style cache control
response.setHeader("Cache-Control", "public, must-revalidate, post-check=0, pre-check=0, max-age=0"); // New-style
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws

// TODO: Should setting the HTTP headers be moved up to the portal level as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
log.debug("dispatching path: " + req.getPathInfo() + " to: " + target + " context: "
Expand Down
5 changes: 1 addition & 4 deletions jsf/jsf-tool/src/java/org/sakaiproject/jsf/util/JsfTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws

// TODO: Should setting the HTTP headers be moved up to the portal level as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
log.debug("dispatching path: " + req.getPathInfo() + " to: " + target + " context: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static void downloadSpreadsheetData(List<List<Object>> spreadsheetData, S
*/
private static void protectAgainstInstantDeletion(HttpServletResponse response) {
response.reset(); // Eliminate the added-on stuff
response.setHeader("Pragma", "public"); // Override old-style cache control
response.setHeader("Cache-Control", "public, must-revalidate, post-check=0, pre-check=0, max-age=0"); // New-style
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws

// TODO: Should setting the HTTP headers be moved up to the portal level as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
log.debug("dispatching path: " + req.getPathInfo() + " to: " + target + " context: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws

// TODO: Should setting the HTTP headers be moved up to the portal level as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
log.debug("dispatching path: " + req.getPathInfo() + " to: " + target + " context: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ protected PrintWriter startResponse(HttpServletResponse res, String title, Strin
{
// headers
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// get the writer
PrintWriter out = res.getWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,7 @@ public void sendResponse(LoginRenderContext rcontext, HttpServletResponse res,
{
res.setContentType(contentType);
}
res.addDateHeader("Expires", System.currentTimeMillis()
- (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// get the writer
PrintWriter out = res.getWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws
// TODO: Should setting the HTTP headers be moved up to the portal level
// as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public void afterPhase(PhaseEvent event) {
if ("true".equals(ajax)) {
try {
ServletOutputStream out = response.getOutputStream();
response.setHeader("Pragma", "No-Cache");
response.setHeader("Cache-Control",
"no-cache,no-store,max-age=0");
response.setDateHeader("Expires", 1);
if (action == null) {
out.println("FAIL");
} else if ("markMessageAsRead".equals(action)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2348,9 +2348,7 @@ public void processExportDataTableByUser() {
httpServletResponse.setHeader("Content-Disposition", "attachment;filename=Stats-Grading-Users.csv");
try {
out = httpServletResponse.getOutputStream();
httpServletResponse.setHeader("Pragma", "No-Cache");
httpServletResponse.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
httpServletResponse.setDateHeader("Expires", 1);

StringBuilder builderHeader = new StringBuilder();
builderHeader.append("Student ID,Name,Authored - New,Authored - Replies,Authored - Total,Read,Unread,Percent Read");
Expand Down Expand Up @@ -2401,9 +2399,7 @@ public void processExportDataTableByTopic() {
httpServletResponse.setHeader("Content-Disposition", "attachment;filename=Stats-Grading-Topics.csv");
try {
out = httpServletResponse.getOutputStream();
httpServletResponse.setHeader("Pragma", "No-Cache");
httpServletResponse.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
httpServletResponse.setDateHeader("Expires", 1);

StringBuilder builderHeader = new StringBuilder();
builderHeader.append("Forum Title,Topic Title,Date,Total Messages");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ else if (EDITOR_LAUNCH_JS.equals(name)) {
res.sendRedirect(editor.getLaunchUrl());
}
else if (EDITOR_BOOTSTRAP_JS.equals(name)) {
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-cache");
res.addHeader("Content-Type", "text/javascript");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1780,10 +1780,7 @@ public void sendResponse(PortalRenderContext rcontext, HttpServletResponse res,
throws IOException {
// headers
res.setContentType(Objects.requireNonNullElse(contentType, "text/html; charset=UTF-8"));
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// get the writer
PrintWriter out = res.getWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,7 @@ public void report(HttpServletRequest req, HttpServletResponse res,
// headers
res.setStatus(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis()
- (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, max-age=0");
res.addHeader("Pragma", "no-cache");

PrintWriter out = null;
try {
Expand Down Expand Up @@ -763,11 +759,7 @@ public void thanksResponse(HttpServletRequest req, HttpServletResponse res)
{
// headers
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis()
- (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, max-age=0");
res.addHeader("Pragma", "no-cache");

PrintWriter out = res.getWriter();
out.println("<!DOCTYPE html>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ protected PrintWriter startResponse(HttpServletRequest req, HttpServletResponse
{
// headers
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// get the writer
PrintWriter out = res.getWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ public Object getProfileImage(OutputStream out, EntityView view, Map<String,Obje
ActionReturn actionReturn = new ActionReturn("UTF-8", image.getMimeType(), out);

Map<String,String> headers = new HashMap<>();
headers.put("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
headers.put("Cache-Control","no-cache, must-revalidate, max-age=0");
headers.put("Pragma", "no-cache");
headers.put("Cache-Control","no-store");

actionReturn.setHeaders(headers);

Expand All @@ -231,9 +229,7 @@ public Object getProfileImage(OutputStream out, EntityView view, Map<String,Obje
if(StringUtils.isNotBlank(url)) {
try {
HttpServletResponse res = requestGetter.getResponse();
res.addHeader("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
res.addHeader("Cache-Control","no-cache, must-revalidate, max-age=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control","no-store");
res.sendRedirect(url);
} catch (IOException e) {
throw new EntityException("Error redirecting to external image for " + id + " : " + e.getMessage(), ref.getReference());
Expand Down Expand Up @@ -483,9 +479,7 @@ public Object getNamePronunciation(OutputStream out, EntityView view, Map<String
try {
HttpServletResponse response = requestGetter.getResponse();
HttpServletRequest request = requestGetter.getRequest();
response.setHeader("Expires", "0");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Cache-Control", "no-store");
response.setContentType(mtba.getMimeType());

// Are we processing a Range request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,7 @@ protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws

// TODO: Should setting the HTTP headers be moved up to the portal level as well?
res.setContentType("text/html; charset=UTF-8");
res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
res.addDateHeader("Last-Modified", System.currentTimeMillis());
res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-store");

// dispatch to the target
log.debug("***5. dispatch, dispatching path: " + req.getPathInfo() + " to: " + target + " context: "
Expand Down
Loading

0 comments on commit 3f9e265

Please sign in to comment.