1
votes

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"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<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.

6
the header is usually capitalized, ie Content-Type: text/html - Knio
You mentioned that this happened "recently", do you remember the changes you made before this happened? - Jaime Garcia
The website code is checked in through subversion, the last change was about two weeks ago. - jinanwow
I tried capitalizing Content-Type but that did not help. Also tried content-type: text/html; charset=utf-8 as well with no luck. - jinanwow

6 Answers

1
votes

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
0
votes

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: 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:

0
votes

I was hitting the same issue. I made a couple of changes and it seemed to work for me.

made the first statement after entering the script as print content-type. used the cgi method 'header' to print the content-type rather than hard-coding.

my $cgi = CGI->new; print $cgi->header('text/html');

I was observing the header through Live HTTP headers in Firefox. All the time before this change it was text/plain chunk. After this change, it changed to text/html and that worked the trick.

Hope this works for you as well.

0
votes

"C" needs to be capitalized in "Content-text"

0
votes

I solved this problem using bash cgi script:

echo -e -n  "Content-type: text/html\n\n";
0
votes

I just ran in to this issue and the solution was that my code had changed from:

print """Content-Type: text/html\n\n

to:

    print """
    Content-Type: text/html\n\n

The code had been tabbed in and an extra newline had been added.
I used angel_007's method to troubleshoot.