Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

mod_perl give 404 not_found with content

by Jaap (Curate)
on Apr 06, 2011 at 22:20 UTC ( #897899=perlquestion: print w/replies, xml ) Need Help??

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

This cannot be hard at all but my google skills fail me. In this piece of mod_perl code:
if ($sth->rows == 0)
{
        $r->status(404);
        #$r->print("Oops, there seems to be an error.");
        ModPerl::Util::exit(0);
}
I'd like to print the actual document content that comes with the 404 error but whatever i try, Apache serves some standard error document instead. Any idea how i can print the document body right from this piece of code?
  • Comment on mod_perl give 404 not_found with content

Replies are listed 'Best First'.
Re: mod_perl give 404 not_found with content
by Anonymous Monk on Apr 06, 2011 at 23:40 UTC
    404 site:http://perl.apache.org/docs/2.0/
    For example, if a handler wants to return a 404 response, but nevertheless to set a cookie, it has to be: $r->err_headers_out->add('Set-Cookie' => $cookie); return Apache2::Const::NOT_FOUND; If the handler does: $r->headers_out->add('Set-Cookie' => $cookie); return Apache2::Const::NOT_FOUND; the C<Set-Cookie> header won't be sent.
      But my problem is not so much in the headers but in printing the content. Is there an equivalent $r->err_content_out or something?
        Oops that post was by me, forgot to login.
Re: mod_perl give 404 not_found with content
by Khen1950fx (Canon) on Apr 07, 2011 at 00:26 UTC
    You were close. I would try it like this with a double-check:
    #!/usr/bin/perl use strict; use warnings; use ModPerl::Util; use ModPerl::Const -compile => 'EXIT'; eval { my $r; $r->status(0); ModPerl::Util::exit(0); }; warn "Oops, there seems to be an error\n"; exit if $@ && ref $@ == ModPerl::EXIT; warn "Still Running\n";
      I find it hard to believe that sends a 404, much less a custom 404.
        Exactly.
        How do i print the actual document content?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://897899]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2020-09-26 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (142 votes). Check out past polls.

    Notices?