本文介绍了从分块gzip压缩的内容prevent阿帕奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在使用的Apache2 mod_deflate模块,Apache将大块gzip压缩的内容,设置传输编码:分块标头。虽然这将导致更快的下载时间,我不能显示一个进度条。

When using mod_deflate in Apache2, Apache will chunk gzipped content, setting the Transfer-encoding: chunked header. While this results in a faster download time, I cannot display a progress bar.

如果我处理COM pression自己在PHP中,我可以gzip压缩它彻底第一和设置Content-Length头,这样我可以显示进度条给用户。

If I handle the compression myself in PHP, I can gzip it completely first and set the Content-length header, so that I can display a progress bar to the user.

是否有将改变Apache的默认行为,并有Apache的设置,而不是分块的响应Content-Length头,这样我就不必处理COM pression自己的任何设置?

Is there any setting that would change Apache's default behavior, and have Apache set a Content-length header instead of chunking the response, so that I don't have to handle the compression myself?

推荐答案

您也许可以用的以获得足够大,可以在一大块的响应值。

You could maybe play with the sendBufferSize to get a value big enough to contain your response in one chunk.

然后是HTTP的一部分/1.1协议,你可以强制一个HTTP / 1.0响应(所以不是分块:服务器不能发送转移的编码到一个HTTP / 1.0客户端),通过设置在力 - 响应-1.0 在Apache配置。但 PHP打破了这种设置,这是PHP的长期已知的bug,有一个的。

Then chunked content is part of the HTTP/1.1 protocol, you could force an HTTP/1.0 response (so not chunked: "A server MUST NOT send transfer-codings to an HTTP/1.0 client.") by setting the force-response-1.0 in your apache configuration. But PHP breaks this settings, it's a long-known-bug of PHP, there's a workaround.

我们可以尝试修改与头preventing分块内容在客户端的请求,但W3C表示:所有HTTP / 1.1应用程序必须能够接收和德code中的分块传输编码,所以我不认为有喜欢接受和任何头这样可以prevent从分块内容的服务器。然而,你可以尝试设置HTTP / 1.0你的要求,它不是真正的请求的头,它的第一线,应尽可能使用jQuery,肯定。

We could try to modify the request on the client side with an header preventing the chunked content, but w3c says: "All HTTP/1.1 applications MUST be able to receive and decode the "chunked" transfer-coding", so I don't think there's any header like 'Accept' and such which can prevent the server from chunking content. You could however try to set your request in HTTP/1.0, it's not really an header of the request, it's the first line, should be possible with jQuery, certainly.

最后一件事,HTTP / 1.0缺少一个大的事情,在主机头是不是强制性的,验证/ 1.0仍然使用'主'头在HTTP的请求,如果您使用基于域名virtualhosts工作。

Last thing, HTTP/1.0 lacks one big thing, the 'host' headers is not mandatory, verify your requests in HTTP/1.0 are still using the 'host' header if you work with name based virtualhosts.

编辑:通过变通办法引技术,你可以看到,你可以在PHP code调整Apache的ENV。这可以用来强制1.0模式,只为您的特殊gzip压缩的内容,你应该有你完整的应用程序使用它来prevent HTTP / 1.0(或使用请求模式设置HTTP / 1.0为你的gzip请求)。

edit: by using the technique cited in the workaround you can see that you could tweak Apache env in the PHP code. This can be used to force the 1.0 mode only for your special gzipped content, and you should use it to prevent having you complete application in HTTP/1.0 (or use the request mode to set the HTTP/1.0 for you gzip requests).

这篇关于从分块gzip压缩的内容prevent阿帕奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:21