Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I *prevent* Apache2 from setting the Content-Type header?

I have a CGI script that prints the following on stdout:

print "Status: 302 Redirect\n";
print "Server: Apache-Coyote/1.1\n";
print "Location: $redirect\n";
print "Content-Length: 0\n";
print "Date: $date\n\n";

Where $redirect and $date are reasonable values. What Apache2 actually sends also includes a Content-Type: header (text/plain). I've commented out the DefaultType in the server configuration file.

I'm trying to debug a downstream problem that arises when no Content-Type: header is sent. So what magic incantation do I have to perform to prevent Apache2 from adding the content type header?

like image 604
Norm Avatar asked Mar 11 '10 20:03

Norm


2 Answers

According to my (admittedly brief) reading of server/protocol.c and server/core.c, you cannot.

It always defaults to DefaultType (text/plain by default) if that header is not present.

like image 127
ceri Avatar answered Sep 18 '22 12:09

ceri


Even if we delete the Content-Type header from the request via the "Header unset Content-Type" directive, apache regenerates the Content-Type header from another field of the request structure. Therefore, we first force that other field to a reserved value, in order to prevent the header regeneration, then we remove the Content-Type via the "Header unset" directive.

For apache2.2:

Header set Content-Type none
Header unset Content-Type

For apache2.4:

Header set Content-Type ""
Header unset Content-Type
like image 23
srn Avatar answered Sep 16 '22 12:09

srn