Java放气响应 [英] Java deflate response
问题描述
大家好我想为 tomcat 制作一个过滤器来缩小某些 MIME 类型的所有响应.有什么指导方针吗?
Hello all I want to make a filter for tomcat to deflate all responces of certain MIME type. Any guidelines?
...
String ae = request.getHeader("accept-encoding");
if (ae != null && ae.indexOf("deflate") != -1) {
deflate response...?????
}
chain.doFilter(request, res);
推荐答案
不要在自制的 Filter
中这样做.在服务器级别配置它.例如 Apache Tomcat,只需将 compression="on"
添加到
元素在 /conf/server.xml
.只要客户端接受它,它就会响应 GZIP(GZIP 是基于 deflate 的,而且只要支持 deflate,几乎每个客户端都支持它).
Don't do that in a homebrewed Filter
. Configure it at server level. In case of for example Apache Tomcat, just add compression="on"
to <Connector>
element in /conf/server.xml
. It will GZIP responses whenever client accepts it (GZIP is based on deflate and practically every client supports it whenever deflate is supported).
<Connector compression="on">
仅此而已.如有必要,您可以通过 compressableMimeType
属性配置 MIME 类型.
That's all. You can if necessary configure mime types by compressableMimeType
attribute.
这篇关于Java放气响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!