ModPerl::Registry and custom error documents

ModPerl::Registry and custom error documents

am 17.09.2009 12:13:47 von Andreas Mock

Hi all,

I searched and googled around for a while but couldn't find a solution for
the following question.

We're using ModPerl::Registry (PerlOptions +ParseHeaders)
in combination with mod_perl to serve our pages in a CGI like
environment. This has the advantage for us to have only a very very
small layer of integration between the scripts an the special runtime
environment.

Now we want to serve custom made error documents and thought
naively to get it work by just setting the status to the error code
and serving a html-page as it works with a normal status 200 page.

But this doesn't work. It seams that apache jumps right into the
error handling stuff as soon as a status code >= 400 is seen.

How can we dynamically create own error documents without using
the lower level mod_perl/apache api? Is there a simple way?
How can we achieve that?

Best regards
Andreas Mock

Re: ModPerl::Registry and custom error documents

am 17.09.2009 13:11:14 von torsten.foertsch

On Thu 17 Sep 2009, Andreas Mock wrote:
> How can we dynamically create own error documents without using
> the lower level mod_perl/apache api? Is there a simple way?
> How can we achieve that?

A very simple registry script:

#!/usr/bin/perl

use strict;

my $r=shift;

$r->status($r->args);
exit;

Then you can configure ErrorDocuments, e.g.

ErrorDocument 404 http://huhu.com
ErrorDocument 500 "dumm gloffe"

Now try it out:

A 404 will be translated into a redirect:

$ curl http://localhost/etest?404 -v
* About to connect() to localhost port 80 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 80 (#0)
> GET /etest?404 HTTP/1.1
> User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0
OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10
> Host: localhost
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Thu, 17 Sep 2009 11:05:19 GMT
< Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13
OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1
mod_perl/2.0.5threading3 Perl/v5.10.0
< Location: http://huhu.com
< Content-Length: 199
< Content-Type: text/html; charset=iso-8859-1
<


302 Found

Found


The document has moved .



* Connection #0 to host localhost left intact
* Closing connection #0


a 403 sends the normal error page

$ curl http://localhost/etest?403 -v
* About to connect() to localhost port 80 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 80 (#0)
> GET /etest?403 HTTP/1.1
> User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0
OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10
> Host: localhost
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Date: Thu, 17 Sep 2009 11:05:58 GMT
< Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13
OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1
mod_perl/2.0.5threading3 Perl/v5.10.0
< Content-Length: 207
< Content-Type: text/html; charset=iso-8859-1
<


403 Forbidden

Forbidden


You don't have permission to access /etest
on this server.



* Connection #0 to host localhost left intact
* Closing connection #0

and a 500 delivers a custom error message:

$ curl http://localhost/etest?500 -v
* About to connect() to localhost port 80 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 80 (#0)
> GET /etest?500 HTTP/1.1
> User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0
OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10
> Host: localhost
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Date: Thu, 17 Sep 2009 11:09:19 GMT
< Server: Apache/2.2.13 (Unix) proxy_html/3.0.1 mod_ssl/2.2.13
OpenSSL/0.9.8h DAV/2 SVN/1.6.4 mod_apreq2-20090110/2.7.1
mod_perl/2.0.5threading3 Perl/v5.10.0
< Content-Length: 11
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<
* Closing connection #0
dumm gloffe

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: ModPerl::Registry and custom error documents

am 05.10.2009 18:23:14 von Andreas Mock

> -----Ursprüngliche Nachricht-----
> Von: "Torsten Foertsch"
> Gesendet: 17.09.09 13:14:16
> An: modperl@perl.apache.org
> CC: Andreas Mock
> Betreff: Re: ModPerl::Registry and custom error documents


> On Thu 17 Sep 2009, Andreas Mock wrote:
> > How can we dynamically create own error documents without using
> > the lower level mod=5Fperl/apache api=3F Is there a simple way=3F
> > How can we achieve that=3F
>=20
>=20
> Then you can configure ErrorDocuments, e.g.
>=20
> ErrorDocument 404 http://huhu.com
> ErrorDocument 500 "dumm gloffe"

Hi Torsten, hi all,

ok, this seems to be the simple case.
Thank you for this answer.

Is there another way to create custom ErrorDocuments based
on the return value of a ModPerl::Regisry script as long as the
script has not printed to stdout yet=3F

Best regards
Andreas