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: head开发者_如何学Cer (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?
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
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.
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.
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.
You can try with the directive:
ResponseHeader unset Content-Type
As I read the Apache docs in question, what you want may actually be
Header unset Content-Type
Hope this does it!
精彩评论