views:

97

answers:

2

I currently have an internal website that is running Apache. It is serving some cgi script webpages (perl code). Recently in Firefox and Chrome it is starting to show plain text version of the HTML code. In Internet Explorer it renders the cgi files as HTML, but in Chrome and Firefox it is rendered as plain text.

In the perl code I have the following:

#!/usr/bin/perl --
#
#Prints the HTML MIME TYPE FOR WEB BROWSERS.
print "content-type: text/html\n\n";
print <<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
<html xmlns="http://www.w3.org/1999/xhtml"&gt; 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Statistics</title> 

--- OUTPUT SNIPPED ---

HTML

Using an application for firefox, I am seeing the response header as being text/plain instead of text/html.

I am not sure if it could have possibly be an Apache config or if its something that is missing for the content type.

A: 

Try adding a complete HTTP header. Instead of just

print "content-type: text/html\n\n";

Try

print "HTTP/1.0 200 OK";
print "content-type: text/html\n\n";

See related question: http://stackoverflow.com/questions/308059/why-do-i-need-to-explicitly-output-the-http-header-for-iis-but-not-apache

and reference: http://search.cpan.org/~lds/CGI.pm-3.42/CGI.pm#CREATING_A_STANDARD_HTTP_HEADER:

evilertoaster
This did not work either.
jinanwow
+1  A: 

This was a workaround but it appears to have fixed the issue:

In the apache host configuration file I added the line for the cgi-bin directory:

DefaultType text/html
jinanwow