在播放结果上设置HTTP标头(如过期) - 以及如何处理ETag?

时间:2012-05-12 15:10:55

标签: playframework

如何在play 2.0中的结果对象中设置Http头?

我想设置Cache控件(expire)ala: 缓存控制 PUBLIC,max-age = 2592000

检查ET标签并返回正确响应的最佳方法是什么?

一直在这里看,但没有看到任何东西: http://www.playframework.org/documentation/2.0.1/JavaActions

提前谢谢 托马斯·维尔维克

1 个答案:

答案 0 :(得分:5)

您需要查看JavaResponse部分...

http://www.playframework.org/documentation/2.0.1/JavaResponse

从文档中设置缓存控制的示例是

public static Result index() {
  response().setContentType("text/html");
  response().setHeader(CACHE_CONTROL, "max-age=3600");
  response().setHeader(ETAG, "xxx");
  return ok("<h1>Hello World!</h1>");
}
相关问题