我有一个独立的码头应用程序。过去,对 Jetty 的请求都带有 expires 标头:
Expires: Thu, 01 Jan 1970 00:00:00 GMT
这是一个与我设置的不同的过期标题。我无法弄清楚为什么会这样?我在 servlet 过滤器中按如下方式设置过期(以及其他标头):
public class AuthorisationFilter implements Filter {
public void init (FilterConfig config) throws ServletException {
expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
expires.setTimeZone(TimeZone.getTimeZone("GMT"));
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// ....
if(url.endsWith(".eot") || url.endsWith(".ttf") || url.endsWith(".woff")) {
response.setHeader("Expires", expires.format(new Date(new Date().getTime()+(1000*86400))));
} else if(url.endsWith(".css") || url.endsWith(".pdf") || url.endsWith(".png") || url.endsWith(".gif") || url.endsWith(".jpg") || url.endsWith(".ico")) {
response.setHeader("Expires", expires.format(new Date(new Date().getTime()+(1000*500))));
} else {
response.setHeader("Expires", "Sat, 6 May 1995 1:00:00 GMT");
}
chain.doFilter(request, response);
}
我正在注册 servlet 过滤器,如下所示:
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(server, "/", false, false);
FilterHolder f = new FilterHolder(new UrlFilter(jee));
context.addFilter(f, "/*", null);
f = new FilterHolder(new AuthorisationFilter(jee);
context.addFilter(f, "/*", null);