简体   繁体   English

如何使用Apache禁用Content-Length响应头?

[英]How to disable the Content-Length response header with Apache?

Let me preface this question by stating that I only want to temporarily disable the header and am fully aware of the implications to browsers, cache mechanisms, etc if the header is not present. 让我通过声明我只想暂时禁用标头并且完全了解对浏览器,缓存机制等的影响(如果标头不存在)来说明这个问题。

I have need to test some caching behavior when the Content-Length header is not present in an HTTP response. 当HTTP响应中不存在Content-Length标头时,我需要测试一些缓存行为。 Is there a way to disable the header? 有没有办法禁用标题?

My first attempt was to simply try to set it to 0 using PHP and header("Content-Length: 0", true); 我的第一次尝试是简单地尝试使用PHP和header("Content-Length: 0", true);将其设置为0 header("Content-Length: 0", true); but this is not the same as completely removing the header from the response. 但这与从响应中完全删除标头不同。

Is it possible to disable/remove the header? 是否可以禁用/删除标题?

Adding Content-Length is something marked in RFC 2616 (HTTP 1.1) as SHOULD. 添加Content-Length是RFC 2616(HTTP 1.1)中标记为SHOULD的内容。 That means web servers generally are designed not to leave it out. 这意味着Web服务器通常被设计为不会遗漏它。

For instance with Apache HTTP Server you have to modify modules/http/http_filters.c. 例如,对于Apache HTTP Server,您必须修改modules / http / http_filters.c。 Searching for Content-Length from the source file practically shows you how to unset it forcibly (take a closer look at around line 1255). 从源文件中搜索Content-Length实际上向您展示了如何强行取消它(仔细查看第1255行)。 Just add the unset to the end of the filter chain and you're set. 只需将未设置添加到过滤器链的末尾即可。

Your other alternative is to use an other web server besides Apache that is either easier to modify or doesn't respect RFC 2616 as well. 您的另一种选择是使用除Apache之外的其他Web服务器,它更容易修改或不遵守RFC 2616。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM