beaker121 has asked for the wisdom of the Perl Monks concerning the following question:

When I turn on mod_perl, my printed Content-type headers like this are not being parsed: print "Content-Type: text/html\n\n"; My website works in Firefox, but other (less tolerant) browsers like Chrome just print the source code with Content-Type: text/html also printed at the top. Developers tools show the Content-type header is missing. This is mod_perl/2.0.11 and I have +ParseHeaders in my apache config like so:
<VirtualHost myserverip:443> ServerAdmin webmaster@mysite.com DocumentRoot /var/www/mysite.com/public_html ServerName mysite.com ErrorLog /var/log/httpd/mysite.com-error_log CustomLog /var/log/httpd/mysite.com-access_log common <Directory "/var/www/mysite.com/public_html"> AddHandler perl-script .cgi .pl .pm PerlResponseHandler ModPerl::PerlRunPrefork PerlOptions +ParseHeaders Options +ExecCGI -Indexes DirectoryIndex disabled AllowOverride All Order allow,deny Allow from all <IfModule mod_rewrite.c> RewriteEngine On RewriteOptions inherit # lots of mod_rewrite stuff in here # </IfModule> </Directory> </VirtualHost>
Any ideas how I can fix this? thanks

Replies are listed 'Best First'.
Re: headers not being parsed with mod_perl
by hippo (Archbishop) on May 07, 2023 at 08:28 UTC
    Any ideas how I can fix this?

    Yes. The web protocol is HTTP. In HTTP the headers and body are separated by a blank line. Once you've printed the blank line, everything which follows is body, not header. Output all your headers before the first blank line and the problem is solved.


    🦛

      Thank you.
Re: headers not being parsed with mod_perl
by beaker121 (Novice) on May 06, 2023 at 22:02 UTC
    It looks like this may be an issue with the code. I moved the bit that prints the header to earlier in the code and it now works, but the cookies printed later are now showing as text. I guess mod_perl isn't keen on having print statements for these things littered around the code, so I will have to try and unpick everything.