Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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); but this is not the same as completely removing the header from the response.

Is it possible to disable/remove the header?

like image 832
Structure Avatar asked Oct 28 '25 18:10

Structure


1 Answers

Adding Content-Length is something marked in RFC 2616 (HTTP 1.1) as SHOULD. That means web servers generally are designed not to leave it out.

For instance with Apache HTTP Server you have to modify 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). 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.

like image 68
erloewe Avatar answered Oct 30 '25 07:10

erloewe