【发布时间】:2016-07-01 06:29:49
【问题描述】:
我有一个带有图像的 GET 响应:
@GET
@Path("{id}/thumbnail")
public Response readThumbnailById(@PathParam("id") String id, @QueryParam("serviceContext") EIServiceContext serviceContext) throws BadRequestRestException {
try {
serviceContextServices.setFullContext(serviceContext);
byte[] thumbnail = documentClientWebServices.readThumbnailById(id);
CacheControl cc = new CacheControl();
cc.setMaxAge(2592000);
cc.setPrivate(true);
ResponseBuilder builder = Response.ok(thumbnail,"image/png");
builder.cacheControl(cc);
return builder.build();
} catch (XECMException ex) {
throw new BadRequestRestException(ex);
} catch (ComponentException ex) {
XECMRestException e = new XECMRestException(ex);
return Response.noContent().entity(e.getEiResultStatus()).build();
}
}
我希望客户端浏览器自动缓存我的图像,
但是图片没有缓存,
Chrome 的响应头给我看:
HTTP/1.1 200 OK
Content-Encoding: gzip
Expires: 0
Cache-Control: no-cache, no-store, must-revalidate
Cache-Control: no-transform, max-age=2592000, private
X-Powered-By: Undertow/1
Server: WildFly/10
Pragma: no-cache
Date: Fri, 01 Jul 2016 05:57:21 GMT
Connection: keep-alive
Content-Type: image/png
Content-Length: 8727
这是因为重复的Cache-Control
如何删除第一个 Cache-Control 条目?
谢谢
【问题讨论】:
-
我在我的机器上尝试了 RESTEasy(我使用的是 3.0.9 Final),但没有这个问题。您是否有一些
ContainerResponseFilter可能会在您的回复中添加Cache-Control标头?
标签: java rest caching resteasy