CGI::Application

software development

#1

Hi all,
I am getting a ‘premature end of headers’ error from a cgi script that inherits
from CGI::Application. I get that this means (I think) that the HTTP headers
are not being sent properly, but CGI::Application is supposed to be handling that.

Has anyone else had, and resolved this problem?

The same set of scripts, etc. works fine on my own machine Apache2/Ubuntu

Thanks, for any help.


#2

You’re right, the HTTP headers are not being sent properly.

Keep in mind that Apache is recieving output provided by the perl program. The perl program is interpreting, compiling and running Perl code. The perl program is not automatically going to spit out a valid set of HTTP headers. If it doesn’t get a chance to run Perl code that does, you’re going to have output that Apache doesn’t like, especially if it encounters an error parsing or compiling the Perl code.

You can try using this code in your instance script:

BEGIN {
print “Content-type: text/plain\n\n”;
}

Or you can use CGI::Carp. You can also try running the script from a shell given the script will work without a proper CGI environment.

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#3

Thanks for the reply Atropos.

Contrary to my first assumption, it’s not a problem with CGI::Application.
I eliminated as many factors as I could - just vanila perl print to STDOUT;
and, at your suggestion wrapped the headder line in a BEGIN block.

The result is the same. when run from the cmdlne i get:

[code]Content-Type: text/plain

Not evem CGI.pm

Not even CGI.pm

[/code]but when invoked from a link in html I get internal server error with a premature end of headers error log entry. As you said, when called from Apache the script is not even compiling. I'm stumped as to why though.

The script is file mode 755, it is under the DocumentRoot, the shebang
line is ‘#!/usr/local/bin/perl -w’, what am I missing? Is there some additional
configuration that I have not done?

Thanks again.


#4

Found my problem.

I had misunderstood the requirements for suexec.
I had my perl (cgi) scripts with perms 755, but not the containing directory.

suexec requires that both the script and the parent dir have file
permissions 755 (rwxr-xr-x) in order to run.

Hope this helps some other n00b like myself.