Norm
Norm

Reputation: 1036

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?

Upvotes: 5

Views: 5971

Answers (6)

srn
srn

Reputation: 51

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

Upvotes: 4

Jan Hertsens
Jan Hertsens

Reputation: 321

If all you are trying to do is prep a very specific test case server-side, you can always "cheat" by pre-baking output in a text file and having netcat listen for connections on some port.

I use that trick when I want to be 100% sure of each byte that the server sends.

Upvotes: 1

karlcow
karlcow

Reputation: 6972

RemoveType will stop sending a content type with the resource.

Addendum

<Files defaulttypenone.txt>
DefaultType None 
</Files>
<Files removetype.txt>
RemoveType .txt
</Files>
<Files forcetype.txt>
ForceType None
</Files>

Tested on my own server, these three solutions and none worked. They all returned text/plain.

Upvotes: 1

ceri
ceri

Reputation: 62

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.

Upvotes: 3

user135286
user135286

Reputation:

As I read the Apache docs in question, what you want may actually be

Header unset Content-Type

Hope this does it!

Upvotes: 0

Maurice Perry
Maurice Perry

Reputation: 32831

You can try with the directive:

ResponseHeader unset Content-Type

Upvotes: 0

Related Questions