/
GWTCacheControlFilter.java
54 lines (45 loc) · 1.69 KB
/
GWTCacheControlFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.zanata.servlet;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* {@link Filter} to add cache control headers for GWT generated files to ensure
* that the correct files get cached.
* <p>
* From
* http://seewah.blogspot.com.au/2009/02/gwt-tips-2-nocachejs-getting-cached
* -in.html
* <p>
* Modified to follow GWT recommended headers more closely:
* https://developers.google
* .com/web-toolkit/doc/latest/DevGuideCompilingAndDebugging#perfect_caching See
* also http://palizine.plynt.com/issues/2008Jul/cache-control-attributes/
*
* @author See Wah Cheng
* @author Sean Flanigan <sflaniga@redhat.com>
* @created 24 Feb 2009
*/
public class GWTCacheControlFilter extends CacheControlFilter {
public void destroy() {
}
public void init(FilterConfig config) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String requestURI = httpRequest.getRequestURI();
if (requestURI.contains(".cache.")) {
addCacheHeader(httpResponse);
} else if (requestURI.contains(".nocache.")) {
addNoCacheHeader(httpResponse);
}
filterChain.doFilter(request, response);
}
}