【问题标题】:How to disable Content-Length on LAMP如何在 LAMP 上禁用 Content-Length
【发布时间】:2015-10-10 11:48:50
【问题描述】:

我需要禁用 Content-length 的发送并在标头中进行其他不同的设置。如何在 LAMP 配置上执行该操作?

反正我要变成这样

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:text/html
Date:Tue, 21 Jul 2015 05:58:49 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=15, max=97
Pragma:no-cache
Server:Apache
Transfer-Encoding:chunked

但现在我有了这个

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Language:ru-RU
Content-Length:2640
Content-Type:text/html; charset=utf-8
Date:Tue, 21 Jul 2015 05:58:44 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=95
Pragma:no-cache
Server:Apache/2.2.22 (Debian)
Vary:Accept-Encoding
X-Powered-By:PHP/5.4.41-0+deb7u1

【问题讨论】:

    标签: php apache http-headers lamp


    【解决方案1】:

    假设您希望在 PHP 中完成此操作(我从标题中猜测您正在使用 PHP),您需要告诉 httpd 编码是分块的:

    <?php
      header("Transfer-encoding: chunked");
      flush();
    ?>
    

    这已经在 SO 上解决了:How to make PHP generate Chunked response

    虽然您可以使用 PHP 执行此操作,但我建议您不要对静态文件执行此操作,因为这会破坏协议的全部意义。

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 2013-12-18
      • 2018-08-27
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      相关资源
      最近更新 更多