public class ResponseHeaderFilter extends Object implements javax.servlet.Filter
One particular header you you may wish to deal with is "Cache-Control: no-cache" This is a problem with Tomcat when security is used. Continue reading for further details.
If a web app has a <security-constraint> in its web.xml, Tomcat will add a Cache-Control header to every file it serves from that location. This header will prevent browsers from caching the file locally and this drastically slows down Hudson page load times.
To enable this filter, edit the web.xml file to include:
<filter>
<filter-name>change-headers-filter</filter-name>
<filter-class>hudson.ResponseHeaderFilter</filter-class>
<init-param>
<param-name>Pragma</param-name>
<param-value>public</param-value>
</init-param>
<init-param>
<param-name>Cache-Control</param-name>
<param-value>max-age=86400, public</param-value>
</init-param>
</filter>
And down below that:
<filter-mapping>
<filter-name>Headers</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
In the case of the tomcat cache problem, it is important that the url-pattern for the filter matches the url-pattern set for the security-constraint.
| Constructor and Description |
|---|
ResponseHeaderFilter() |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse resp,
javax.servlet.FilterChain chain) |
void |
init(javax.servlet.FilterConfig filterConfig) |
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionpublic void doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse resp,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.FilterIOExceptionjavax.servlet.ServletExceptionpublic void destroy()
destroy in interface javax.servlet.FilterCopyright © 2019. All rights reserved.