It seems that using CGI, it is too late return a true 404 once the script is processing the request. It's possible to still send output that returns "page not found" text, but the HTTP status code will be 200.

More recently, I learned that with mod_perl, I learned that I can get
the system to return a true 404, so I updated my CGI::Application logic to do that when possible:

 if (exists $ENV{MOD_PERL}) {
   $self->header_add( -status => 404 );
   return '';
 }
 else {
    return $self->error(title => 'Page not found')
 }

However, I don't think I'm doing the ideal think in mod_perl, because it
behaves strangely in some cases. Two specific cases:

If I use GET on the command line, instead of 404, I'll get back this:
"500 EOF when chunk header expected"

Unless I fallback to HTTP 1.0:

PERL_LWP_USE_HTTP_10=1 GET ...

But for some reason, setting this environment variable was not working
for with Test::WWW::Mechanize.

More troubling is the behavior I see in the browser: The first time I
access the script that would through this 404 in mod_perl, it works.
Then for attempts 2 through 6 return internal server errors complaining
about "can't locate modules". Starting on load 7, the pages are returned
reliably with the 404 error. WTF?

( This is with Apache 1.3x and mod_perl 1.x )

The approach of CGI::Application::Dispatch is to also return the "404"
code, but also returns the body content along with it. In my case, I'm
hoping to trigger the internal ErrorDocument 404 page instead of
re-inventingt that wheel.

What am I missing?

Thanks!

   Mark

Reply via email to