如何禁用LAMP上的Content-Length

时间:2015-07-21 06:42:26

标签: php apache http-headers lamp

我需要禁用内容长度的发送,并在标题中进行其他不同的设置。如何在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

1 个答案:

答案 0 :(得分:0)

假设您希望在PHP中完成此任务(我猜测您正在使用PHP的标头),您需要告诉httpd编码是否已分块:

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

之前在SO:How to make PHP generate Chunked response

上已经解决了这个问题

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