Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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->print("Oops, there seems to be an error.");
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:
    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.
        How do i print the actual document content?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2021-09-22 21:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found