我正在尝试在我们的网站上使用bigpipe概念。 这意味着尝试发送响应块,而不是作为一个整体发送,以便用户认为该页面是快速的。 我成功地通过在java中的响应对象上使用flushBuffer方法来做到这一点。 但是现在当我尝试用apache mod_deflate模块压缩内容时,分块会丢失。
这里是用来压缩内容的apache的configuration
**
开始mod_deflateconfiguration
DeflateBufferSize 100 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript browserMatch ^Mozilla/4 gzip-only-text/html browserMatch ^Mozilla/4.0[678] no-gzip browserMatch bMSIE !no-gzip !gzip-only-text/html DeflateFilterNote Input input_info DeflateFilterNote Output output_info DeflateFilterNote Ratio ratio_info LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate CustomLog /var/log/httpd/deflate_log deflate
结束mod_deflateconfiguration**
这是在apache中打开deflate时的响应头
连接:保持活动
内容编码:gzip
内容长度:7916
内容types:text / html的; 字符集= UTF-8
date:2012年1月27日星期五20:11:11 GMT
保持活跃:超时= 300,最大= 3997
服务器:Apache
有所不同:接受编码
在apache中closuresdeflate时的响应头
连接:保持活动
内容types:text / html的; 字符集= UTF-8
date:2012年1月27日星期五20:21:14 GMT
保持活跃:超时= 300,最大= 3997
服务器:Apache / 2.2.3(CentOS)
传输编码:分块
正如你在上面看到的,只有压缩closures时,chunking才能工作。 我正在网上search有关这个和人们build议减lessDeflateBufferSize值。 我减less了100个字节的值,你可以在我的apacheconfiguration中看到,但仍然没有解决问题。 DeflateBufferSize设置为100字节意味着响应缓冲在Apache中,直到收到100字节,然后压缩。
我正在查看与旧的Apache 1.3捆绑在一起的mod_gzip模块,该模块有一个下面的指令,允许分块的内容被压缩。
mod_gzip_dechunk是的
有没有人知道mod_deflate与Apache 2.x捆绑这样的指令?
还是有人知道如何压缩分块的内容?
其实我找到了解决办法。 我曾经创建一个新的对象GZipOutputStream每次刷新不同的块。 相反,您应该只创建一个GZipOutputStream对象,然后使用该对象来压缩响应的所有块。 另外我把GZipOutputStream的包装。 这里是我用google搜索的包装。
public class GZIPFlushableOutputStream extends GZIPOutputStream { public GZIPFlushableOutputStream(final OutputStream out) throws IOException { // Using Deflater with Nowrap == true will ommit headers and trailers super(out); } private static final byte[] EMPTYBYTEARRAY = new byte[0]; /** * Insure all remaining data will be output. */ public void flush() throws IOException { /** * Now this is tricky: We force the Deflater to flush its data by * switching compression level. As yet,a perplexingly simple workaround * for * * http://developer.java.sun.com/developer/bugParade/bugs/42557 43.html */ def.setInput(EMPTYBYTEARRAY,0); def.setLevel(Deflater.NO_COMPRESSION); deflate(); def.setLevel(Deflater.DEFAULT_COMPRESSION); deflate(); out.flush(); } }
我的理解是,你需要“整个”文件来压缩它。 您可以将其发送出去或压缩发送。 mod_gzip_dechunk选项似乎不再存在 – 请参阅mod_deflate文档 。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。