码头掉落缓存控制 [英] Jetty drops Cache-Control

查看:266
本文介绍了码头掉落缓存控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jetty上部署servlet时遇到问题.看来Jetty只是丢弃了servlet中生成的 Cache-Control (和 Pragma )标头.

I'm having problem with deploying servlet on Jetty. It seems that Jetty simply drops Cache-Control (and Pragma) headers produced in servlet.

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似乎吞下了这些标题.

All headers (esp. Cache-Control and Pragma) are as expected when I deploy such servlet into Tomcat. But Jetty seems to swallow these headers.

有什么建议吗?

推荐答案

使用使用测试servlet

With test 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网络检查面板显示的内容.

It works here, this is what the Chrome network inspection panel shows.

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所显示的...

And this is what curl shows ...

$ 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

有效.

显然,还有其他事情正在从您的响应中删除这些标头.寻找诸如过滤器,框架库,高速缓存层,透明代理,普通代理,负载平衡器和/或网络硬件之类的东西作为看似已删除标头的来源.

Apparently something else is removing those headers from your response. Look for things like a filter, a framework library, a cache layer, a transparent proxy, a normal proxy, load balancers, and/or network hardware as your source for your seemingly removed headers.

这篇关于码头掉落缓存控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆