Apache "malformed header" error

Apache "malformed header" error

Post by Jeff Pizi » Wed, 03 May 2000 04:00:00



On trying to serve an html page returned from a cgi, apache complains:
[error][client 192.168.2.4] malformed header from script. Bad
header=<html>: /var/www/cgi-bin/my.cgi

If I run the cgi in the console and capture the output in a file, I can
serve up this document as a static html page. It works fine, except for
the printing of "Content-type: text/html" at the beginning of the
displayed document, as the cgi places this in here and Apache supplies
one for html documents.

Any help or ideas would be greatly appreciated.
Thanks,

Jeff Pizio
Programmer
PageMail, Inc.

 
 
 

Apache "malformed header" error

Post by J.D. Silvest » Wed, 03 May 2000 04:00:00



: On trying to serve an html page returned from a cgi, apache complains:
: [error][client 192.168.2.4] malformed header from script. Bad
: header=<html>: /var/www/cgi-bin/my.cgi

: If I run the cgi in the console and capture the output in a file, I can
: serve up this document as a static html page. It works fine, except for
: the printing of "Content-type: text/html" at the beginning of the
: displayed document, as the cgi places this in here and Apache supplies
: one for html documents.

Assuming perl for your cgi program, ensure that the following line is
executed before you cgi attempts to send output back to the browser.

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

or if you are using the CGI module in perl you could use

$query = new CGI;

print $query->header();

 
 
 

Apache "malformed header" error

Post by Tom Harringto » Thu, 04 May 2000 04:00:00



> On trying to serve an html page returned from a cgi, apache complains:
> [error][client 192.168.2.4] malformed header from script. Bad
> header=<html>: /var/www/cgi-bin/my.cgi

> If I run the cgi in the console and capture the output in a file, I can
> serve up this document as a static html page. It works fine, except for
> the printing of "Content-type: text/html" at the beginning of the

Do I understand correctly that the CGI code is already printing the
Content-type header?

In that case, it sounds like the problem is that there's no space
between the header and the content.  You need to print a blank line
after the content-type header and before the HTML starts.  
Everything up to the first blank line will be taken as a header.

--
Tom Harrington
CrosStor Software, Inc.

 
 
 

1. "malformed header" error (Apache 1.0/SCO) ?

I've recently compiled Apache 1.0.0 under SCO 3.4.2. The system was previously
running 0.6.5, and existing CGI programs in C are not running under the new
service. The error_log contains the message:

[Tue Jan 16 13:41:56 1996] access to /w/cgi-bin/srch failed for dbyrne.aba
soft.co.uk, reason: malformed header from script

I've run the program from the command line, and the output is as expected:

Content: text/html

<HTML>
<HEAD><TITLE>title</TITLE></HEAD>
<BODY>

...

</BODY>
</HTML>

This all appears valid, and the same cgi progs compiled on a Sun running
Solaris 2.4 work fine with the 1.0.0 Server, so it looks like a SCO problem.
When the cgi program exits, it is as a result of a failed select(2) call,
which it doesn't do under 0.6.5. The number of SpareServers/MaxServers etc
does not affect the problem.

The cgi progs are all called from URLs, no SSI involved.
Has anyone seen this or have any ideas ?

Regards,

David
--
David Byrne, Abacus Software, London, UK              Tel: +44 (0)171 603 9877

Here's a koan: If you have ice-cream I will give you some. If you have none,
               I will take it away from you. (it's an ice-cream koan).

2. Dynamic NAT with iptables

3. GETSERVBYNAME()????????????????????"""""""""""""

4. NistNet help.

5. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

6. Bus mastering support for IDE CDROM audio

7. An addition to the "Failed CGI" and "Error Log for Apache" threads

8. Star Office File Management

9. Error during install "Error reading header at xxxx"

10. "error 2 reading header: unknown error" - what is this?

11. Type "(", ")" and "{", "}" in X...

12. "Source Route Failed", "LOGIN FAIL..", "Malformed response", and "Lame server" messages in /var/log

13. APACHE Error: "Signaling Error: error already pending"