我有一张带有图片的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条目?
由于
答案 0 :(得分:1)
在google之后,我发现了一个全球解决方案:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<https-listener name="https" security-realm="UndertowRealm" socket-binding="https"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
<filter-ref name="gzipFilter" predicate="exists['%{o,Content-Type}'] or regex[pattern='(?:application/javascript|text/css|text/html|text/xml|application/json)(;.*)?', value=%{o,Content-Type}, full-match=true]"/>
<filter-ref name="custom-max-age" predicate="exists['%{o,Content-Type}'] or regex[pattern='(?:image/png)(;.*)?', value=%{o,Content-Type}, full-match=true] or path-suffix['.js'] or path-suffix ['.json'] or path-suffix ['.html'] or path-suffix ['.css'] or path-suffix ['.jpg'] or path-suffix ['.jpeg'] or path-suffix ['.png'] or path-suffix ['.gif']"/>
</host>
</server>
<servlet-container name="default" disable-caching-for-secured-pages="false">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
<response-header name="custom-max-age" header-name="Cache-Control" header-value="max-age=86400, public"/>
<gzip name="gzipFilter"/>
</filters>
</subsystem>
关键是:
<servlet-container name="default" disable-caching-for-secured-pages="false">
禁用缓存安全页面之后,没有第一个条目缓存控制:无缓存,无存储,必须重新验证