Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to suppress the default mod_perl error page in legacy CGI script using ModPerl::Registry
    primarykey
    data
    text
    <p>I have a CGI script in Perl that generates HTTP error pages by itself. I am running it under mod_perl via <a href="http://p3rl.org/ModPerl::Registry" rel="nofollow noreferrer">ModPerl::Registry</a>, using the following Apache2 configuration:</p> <pre><code>Alias /perl "/var/www/perl" &lt;Directory "/var/www/perl"&gt; SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options Indexes FollowSymlinks +ExecCGI AllowOverride None Order allow,deny Allow from all &lt;/Directory&gt; </code></pre> <p>Everything is fine, except a little problem: when HTTP status printed in headers is different than 200 (for instance 404), Apache appends a default HTML error document to my own generated response.</p> <p>Take for example the following simple CGI script:</p> <pre class="lang-perl prettyprint-override"><code>#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard :escapeHTML -nosticky); use CGI::Carp qw(fatalsToBrowser); use Apache2::Const qw(:http :common); our $cgi = CGI-&gt;new(); print $cgi-&gt;header(-type=&gt;'text/html', -charset =&gt; 'utf-8', -status=&gt; '404 Not Found'); our $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : ''; print &lt;&lt;"EOF"; &lt;html&gt; &lt;head&gt; &lt;title&gt;die_error_minimal$mod_perl_version &lt;/head&gt; &lt;body&gt; 404 error &lt;/body&gt; &lt;/html&gt; EOF exit; </code></pre> <p>Running it with Apache configuration mentioned above results in</p> <pre class="lang-html prettyprint-override"><code>HTTP/1.1 404 Not Found Date: Sun, 27 Nov 2011 13:17:59 GMT Server: Apache/2.0.54 (Fedora) Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 &lt;html&gt; &lt;head&gt; &lt;title&gt;die_error_minimal mod_perl/2.0.1 &lt;/head&gt; &lt;body&gt; 404 error &lt;/body&gt; &lt;/html&gt; &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt; &lt;html&gt;&lt;head&gt; &lt;title&gt;404 Not Found&lt;/title&gt; &lt;/head&gt;&lt;body&gt; &lt;h1&gt;Not Found&lt;/h1&gt; &lt;p&gt;The requested URL /perl/die_error_minimal.cgi was not found on this server.&lt;/p&gt; &lt;hr&gt; &lt;address&gt;Apache/2.0.54 (Fedora) Server at localhost Port 80&lt;/address&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>Note that replacing <code>exit;</code> in the example CGI script above with either <code>return Apache2::Const::OK;</code> or <code>return Apache2::Const::DONE;</code>, as recommended in "<a href="https://stackoverflow.com/q/1681030/46058">How do I suppress the default apache error document in mod_perl?</a>" question on SO doesn't help -- the result stays the same.</p> <p>What should I fix in my Apache configuration, or what should I add to my CGI script to suppress appending error page by mod_perl / Apache to generated response?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload