RESTEasy-使用重复的缓存控件进行响应-Wildfly10 [英] RESTEasy - Response with duplicated Cache-Control - Wildfly10
本文介绍了RESTEasy-使用重复的缓存控件进行响应-Wildfly10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对图片有GET响应:
@GET@Path("{id}/thumbnail")公共响应readThumbnailById(@PathParam("id")字符串ID,@ QueryParam("serviceContext")EIServiceContext serviceContext)引发BadRequestRestException {尝试 {serviceContextServices.setFullContext(serviceContext);字节[]缩略图= documentClientWebServices.readThumbnailById(id);CacheControl cc = new CacheControl();cc.setMaxAge(2592000);cc.setPrivate(true);ResponseBuilder builder = Response.ok(thumbnail,"image/png");builder.cacheControl(cc);返回builder.build();} catch(XECMException ex){抛出新的BadRequestRestException(ex);} catch(ComponentException ex){XECMRestException e =新的XECMRestException(ex);返回Response.noContent().entity(e.getEiResultStatus()).build();}}
我希望客户端浏览器自动将我的图片缓存,
但是图像没有被缓存
Chrome浏览器的响应标题显示给我:
HTTP/1.1 200 OK内容编码:gzip过期:0缓存控制:无缓存,无存储,必须重新验证快取控制:不做转换,最大年龄= 2592000,专用X-Powered-By:Undertow/1服务器:WildFly/10语用说明:无快取日期:2016年7月1日,星期五,格林尼治标准时间连接:保持活动状态内容类型:image/png内容长度:8727
这是因为复制了Cache-Control
如何删除第一个Cache-Control条目?
谢谢
解决方案
在Google搜寻了很多之后,我发现了一个全局解决方案:
<子系统xmlns ="urn:jboss:domain:undertow:3.0">< buffer-cache name ="default"/><服务器名称=默认服务器">< http-listener name =默认" socket-binding ="http" redirect-socket ="https"/>< https-listener name ="https" security-realm ="UndertowRealm" socket-binding ="https"/><主机名=默认主机"别名=本地主机">< 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}']或regex [pattern ='(?: application/javascript | text/css | text/html | text/xml| application/json)(;.*)?',值=%{o,Content-Type},完全匹配= true]"/>< filter-ref name ="custom-max-age" predicate ="exists ['%{o,Content-Type}']或regex [pattern ='(?: image/png)(;.*)?,值=%{o,Content-Type},完全匹配= true]或路径后缀['.js']或路径后缀['.json']或路径后缀['.html']或路径-后缀['.css']或路径后缀['.jpg']或路径后缀['.jpeg']或路径后缀['.png']或路径后缀['.gif']"/></host></服务器>< servlet-container name ="default" disable-caching-for-secured-pages ="false">< jsp-config/>< websockets/></servlet-container><处理程序><文件名="welcome-content" path ="$ {jboss.home.dir}/welcome-content"/></handlers><过滤器>< 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">
禁用对安全页面的缓存后,没有第一项缓存控制:无缓存,无存储,必须重新验证 >
I have a GET response with an image:
@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();
}
}
And I want the client browser caching my image automatically,
But the image was not cached,
The Response Header of Chrome show me:
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
It is because of the duplicated Cache-Control
How can I remove the first Cache-Control entry?
Thanks
解决方案
After google a lot, I found out, a global solution :
<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>
The key is :
<servlet-container name="default" disable-caching-for-secured-pages="false">
After disable-caching-for-secured-pages, There is no first entry Cache-Control: no-cache, no-store, must-revalidate
这篇关于RESTEasy-使用重复的缓存控件进行响应-Wildfly10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文