I am having an extrememly frustrating experience getting my old mod_perl1
scripts from a RedHat 7.3 server working on a new CentOS4 box with Apache
2.0.52 server with mod_perl 2.0.1 with CGI.pm 3.11
I have a mod_perl script area set tup with
<Directory /home/httpd/facility>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions -ParseHeaders
Options +ExecCGI
SSLRequireSSL
AllowOverride FileInfo AuthConfig Limit
</Directory>
I finally got most of the scripts working after going through
hours of the porting according to the migration documents which I found
very disorganized and incomplete. I finally have all most all scripts
working except for one, which manages a repository of files of different
MIME types and serves them. For this it needs control of the outgoing
HTTP headers to set content-type and content-length and such. But
I cannot get it to work. A short example that shows the problem is:
#!/usr/bin/perl
use CGI qw/:standard :netscape/;
my $filepath "/tmp/foobar.pdf";
my $mimetype = "application/pdf";
my $size = ( -s $filepath );
my $head = header(-type=>$mimetype,-nph=>1,
-Content_length=>$size,-expires=>'now');
print $head;
unless ($ENV{REQUEST_METHOD} eq 'HEAD') {
open(FH,"<$filepath");
my($br,$buf);
while ($br=read(FH,$buf,1024)) { print $buf; }
close(FH);
}
With "PerlOptions -ParseHeaders" set above, this results in the header
being printed at the top of the resulting web page with all the random PDF
data junk after that. Properties on the web page says the web page type is
"text/plain". So something is sending a header before giving me a chance
to even though I have "PerlOptions -ParseHeaders" set.
If I try "PerlOptions +ParseHeaders" the only change is no header
is shown on the resulting web page, just the garbage of data. Properties
still says the server gave a header of content type "text/plain".
How can I get the header I want to be the true HTTP header sent?
--
---------------------------------------------------------------
Paul Raines email: raines at nmr.mgh.harvard.edu
MGH/MIT/HMS Athinoula A. Martinos Center for Biomedical Imaging
149 (2301) 13th Street Charlestown, MA 02129 USA