I seem to be unable to modify the headers using a Servlet filter, but I'm not sure why.
The code looks like this:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
try {
//System.out.println("Intercepted by filter 2");
try {
HttpServletResponse http = (HttpServletResponse)response;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR)+10);
http.setDateHeader("Date", cal.getTime().getTime());
http.setDateHeader("Expires", cal.getTime().getTime());
} catch (ClassCastException ignored) {
System.out.println("ClassCastException");
}
filterChain.doFilter(request, response);
}
catch(ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
It does not print any errors, and I had a System out which confirmed that this filter was being used. It is supposed to set the Expires header to 10 years from now, but all it does is clear out the Expires header so when I look at the image downloaded on the client side and check the header information it shows 'NONE'. I also threw in the Date header for create date and instead of changing the date it too made the header show 'NONE'.
Any idea what's going on?