if(!MyStringUtil.isNullOrEmpty(notCacheUrlList)){
notCacheURLs = notCacheUrlList.split(",");
}
}
@Override
protected void doFilter(final HttpServletRequest request,final HttpServletResponse response, final FilterChain chain)throws AlreadyGzippedException, AlreadyCommittedException,FilterNonReentrantException, LockTimeoutException, Exception
{
if (notCacheURLs == null) {
init();
}
String request_url = request.getRequestURI();
boolean flag = false;
if (notCacheURLs != null && notCacheURLs.length > 0) {
for (String notCacheURL : notCacheURLs) {
if (request_url.contains(notCacheURL.trim())) {
flag = true;
break;
}
}
}
//如果请求的url为不需要缓存的,则执行正常页面转向;否则缓存该页面
if (flag) {
chain.doFilter(request, response);
}else{
String query = request.getQueryString();
if (query != null) {
query = " " + query;
}
log.info("当前请求被缓存:" + request_url + query);
super.doFilter(request, response, chain);
}
}
@SuppressWarnings("unchecked")
private boolean headerContains(final HttpServletRequest request, final String header, final String value) {
logRequestHeaders(request);
final Enumeration accepted = request.getHeaders(header);
while (accepted.hasMoreElements()) {
final String headerValue = (String) accepted.nextElement();
if (headerValue.indexOf(value) != -1) {
return true;
}
}
return false;
}
@Override
protected boolean acceptsGzipEncoding(HttpServletRequest request) {
boolean ie6 = headerContains(request, "User-Agent", "MSIE 6.0");
boolean ie7 = headerContains(request, "User-Agent", "MSIE 7.0");
return acceptsEncoding(request, "gzip") || ie6 || ie7;
}
}