Jetty删除Cache-Control

时间:2014-10-06 09:58:11

标签: servlets http-headers jetty cache-control

我在Jetty上部署servlet时遇到问题。似乎Jetty只是删除了在servlet中生成的 Cache-Control (和 Pragma )标头。

public abstract class Servlet extends HttpServlet {
  ...
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ...
    resp.setHeader("Cache-Control", "private, no-cache");
    resp.setHeader("Pragma", "no-cache");
    ...
  }
  ...
}

当我将这样的servlet部署到Tomcat时,所有头文件(特别是Cache-Control和Pragma)都是预期的。但Jetty似乎吞下了这些标题。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

使用Jetty Distribution 8.0.3.v20111011

使用测试servlet

package example;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class CacheServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        resp.setHeader("Cache-Control", "private, no-cache");
        resp.setHeader("Pragma", "no-cache");

        resp.setContentType("text/plain");
        resp.getWriter().println("Hello Cache Test");
    }
}

它适用于此处,这是Chrome网络检查面板显示的内容。

HTTP/1.1 200 OK
Date: Mon, 06 Oct 2014 14:45:05 GMT
Cache-Control: private, no-cache
Pragma: no-cache
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 17
Server: Jetty(8.0.3.v20111011)

这就是卷曲所显示的......

$ curl --dump-header - http://localhost:8080/cachetest/cachetest
HTTP/1.1 200 OK
Date: Mon, 06 Oct 2014 14:47:51 GMT
Cache-Control: private, no-cache
Pragma: no-cache
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 17
Server: Jetty(8.0.3.v20111011)

Hello Cache Test

有效。

显然其他人正在从您的回复中删除这些标头。寻找过滤器,框架库,缓存层,透明代理,普通代理,负载均衡器和/或网络硬件等内容,作为您看似删除的标头的来源。