Add some logging to the cache filter.
@@ -19,6 +19,8 @@ package io.apicurio.registry.ui.servlets;
import java.io.IOException;
import java.util.Date;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -28,11 +30,14 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.slf4j.Logger;
+
/**
* {@link Filter} to add cache control headers for resources such as CSS and images.
*
* @author eric.wittmann@gmail.com
*/
+@ApplicationScoped
public class ResourceCacheControlFilter implements Filter {
public static void disableHttpCaching(HttpServletResponse httpResponse) {
@@ -47,6 +52,9 @@ public class ResourceCacheControlFilter implements Filter {
return now.getTime() - 86400000L;
}
+ @Inject
+ Logger log;
+
/**
* C'tor
*/
@@ -66,6 +74,7 @@ public class ResourceCacheControlFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String requestURI = ((HttpServletRequest) request).getRequestURI();
+ log.debug("Running cache control filter on: " + requestURI);
Date now = new Date();
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setDateHeader("Date", now.getTime()); //$NON-NLS-1$
@@ -82,9 +91,11 @@ public class ResourceCacheControlFilter implements Filter {
}
if (disableCaching) {
+ log.debug(" |-> Caching is disabled.");
disableHttpCaching(httpResponse);
} else {
// Cache most files for one year
+ log.debug(" |-> Caching for one year.");
httpResponse.setDateHeader("Expires", expiresInOneYear(now)); //$NON-NLS-1$
httpResponse.setHeader("Cache-control", "public, max-age=31536000"); //$NON-NLS-1$ //$NON-NLS-2$
}
