Java deflate response

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:06:36

问题


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);

回答1:


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">

That's all. You can if necessary configure mime types by compressableMimeType attribute.

See also:

  • Apache Tomcat Configuration Reference - The HTTP Connector


来源:https://stackoverflow.com/questions/3813281/java-deflate-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!