RESTEasy - 使用重复的缓存控制进行响应 - Wildfly10
RESTEasy - Response with duplicated Cache-Control - Wildfly10
我有一个带有图像的 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重复了
如何删除第一个缓存控制条目?
谢谢
经过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">
在 disable-caching-for-secured-pages 之后,没有第一个条目 Cache-Control: no-cache, no-store, must-重新验证
我有一个带有图像的 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重复了
如何删除第一个缓存控制条目?
谢谢
经过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">
在 disable-caching-for-secured-pages 之后,没有第一个条目 Cache-Control: no-cache, no-store, must-重新验证