Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl CGI.pm: how to suppress content-type header for 304 Not Modified"

Status
Not open for further replies.

petey

Programmer
Mar 25, 2001
383
US
I'm implementing an XML feed in Perl/Apache. If I send a "304 Not Modified" header to the client, CGI.pm's header() function wants to put a Content-Type header in there. If I don't specify one, it sends text/html. If I specify an empty one, it inserts text/plain. I want to leave it out altogether. I haven't had much luck searching Google for this answer. Does anybody know if there's a way to do this?
 
If you're outputting XML, why not set the content-type to "text/xml"?
 
Yeah, I can set it to whatever I want, but I'd like to suppress it.
 
Hi

I think, that is happening after the CGI done its job. I mean, the [tt]Content-type[/tt] is probably appended by the webserver. In which case there is nothing to do from the script. Look at your webserver's documentation.

Feherke.
 
Hmm. Maybe so, but you'd think if Apache was behaving that "intelligently," then it would see the 304 status and know that the Content-type header isn't necessary. Especially since Apache doesn't send Content-type when returning a 304 for a static file, since the response contains no content.
 
Is the existence of the Content-Type making your other header not do what it's supposed to?

For example, I had one site that I moved elsewhere and had a CGI print this out:

Code:
if ($ENV{SERVER_NAME} =~ /aichaos\.com/i) {
	print "Location: [URL unfurl="true"]http://www.f2mb.com/\n"[/URL]
		. "Status: 301 Moved Permanently\n"
		. "Content-Type: text/html\n\n"
		. "<html>\n"
		. "<head>\n"
		. "<title>AiChaos</title>\n"
		. "<script language=\"JavaScript\" type=\"text/javascript\">\n"
		. "self.location = '[URL unfurl="true"]http://www.f2mb.com/';\n"[/URL]
		. "</script>\n"
		. "</head>\n"
		. "<body><a href=\"[URL unfurl="true"]http://www.f2mb.com/\">Continue</a></body>\n"[/URL]
		. "</html>\n";
	exit;
}

So it printed a Location and a 301 status, so that browsers that honor the Location headers can send the redirection and note that it's a permanent change. Browsers that don't honor Location, however, would get an HTML page with both a JavaScript redirection and a normal anchor, linking to the right place.

(I got the tip about sending both Location and Content-Type from some other CGI site about the "301 Moved Permanently" status code)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top