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?


try with: Header unset Content-Length in your .htaccess file

Written by Ivan

Using that with an .htaccess file or httpd.conf it does not seem to be working. I can set headers, but cannot remove Content-Length.

Written by Structure

You can try to hack the apache source code to remove the Content-Length header generation. That's also what Open Source is made for :)

Written by SirDarius

Accepted Answer

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.

Written by erloewe
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki