1 28 29 package com.caucho.filters; 30 31 import com.caucho.config.types.Period; 32 33 import javax.servlet.Filter ; 34 import javax.servlet.FilterChain ; 35 import javax.servlet.FilterConfig ; 36 import javax.servlet.ServletException ; 37 import javax.servlet.ServletRequest ; 38 import javax.servlet.ServletResponse ; 39 import javax.servlet.http.HttpServletResponse ; 40 import java.io.IOException ; 41 42 83 public class AnonymousExpiresFilter implements Filter { 84 87 private long _cacheTime = 2000; 88 89 92 public void setCacheTime(Period period) 93 { 94 _cacheTime = period.getPeriod(); 95 } 96 97 100 public void init(FilterConfig config) 101 throws ServletException 102 { 103 String time = config.getInitParameter("cache-time"); 104 105 if (time != null) { 106 try { 107 _cacheTime = Period.toPeriod(time); 108 } catch (Exception e) { 109 throw new ServletException (e); 110 } 111 } 112 } 113 114 118 public void doFilter(ServletRequest request, ServletResponse response, 119 FilterChain nextFilter) 120 throws ServletException , IOException 121 { 122 if (_cacheTime > 0) { 123 HttpServletResponse res = (HttpServletResponse ) response; 124 125 res.addHeader("Vary", "Cookie"); 126 res.addHeader("Cache-Control", "s-maxage=" + _cacheTime); 127 } 128 129 nextFilter.doFilter(request, response); 130 } 131 132 135 public void destroy() 136 { 137 } 138 } 139 | Popular Tags |