ErrorDocument from a registry script

ErrorDocument from a registry script

am 07.05.2009 17:13:26 von mpeters

I'm pretty sure this should just work and I'm doing something stupid, so any
helpful insults that point me in the right direction would be appreciated :)

I have a registry script that could return a NOT FOUND (404) error. I'm handling
that like so:

Apache->request->status(NOT_FOUND);

The browser does get the 404 HTTP status header, but it does not trigger the
ErrorDocument 404 that is set up, instead just showing the browser's built-in
404 message. PerlSendHeaders is Off and I'm not printing any output.

So what am I missing?

--
Michael Peters
Plus Three, LP

Re: ErrorDocument from a registry script

am 07.05.2009 19:47:24 von mpeters

Michael A. Capone wrote:
> In the spirit of checking off the obvious things... are you sure that
> the ErrorDocument directive is working for other pages? in other words,
> can you open a browser and goto
> http://mydomain.com/this_file_does_not_exist.htm and see your
> ErrorDocument?\

Yes, that's how I know that it's not the browser silently ignoring my
ErrorDocument (which IE is known to do).

Has anyone else done this before or can someone confirm to me that it should
work? Would help to know that I'm not chasing an impossible dream.

--
Michael Peters
Plus Three, LP

Re: ErrorDocument from a registry script

am 07.05.2009 19:47:32 von mcapone

In the spirit of checking off the obvious things... are you sure that
the ErrorDocument directive is working for other pages? in other words,
can you open a browser and goto
http://mydomain.com/this_file_does_not_exist.htm and see your ErrorDocument?

Michael Peters wrote:
> I'm pretty sure this should just work and I'm doing something stupid,
> so any helpful insults that point me in the right direction would be
> appreciated :)
>
> I have a registry script that could return a NOT FOUND (404) error.
> I'm handling that like so:
>
> Apache->request->status(NOT_FOUND);
>
> The browser does get the 404 HTTP status header, but it does not
> trigger the ErrorDocument 404 that is set up, instead just showing the
> browser's built-in 404 message. PerlSendHeaders is Off and I'm not
> printing any output.

Re: ErrorDocument from a registry script

am 07.05.2009 20:20:35 von Perrin Harkins

On Thu, May 7, 2009 at 11:13 AM, Michael Peters wro=
te:
> I have a registry script that could return a NOT FOUND (404) error. I'm
> handling that like so:
>
> =A0Apache->request->status(NOT_FOUND);

You also need to return the correct code from the handler. This is
not simple to do from Registry. Have a quick look at the list
archives for things related to Registry and 304/404 handling.

Apache::RedirectLogFix might be the ticket for you.

- Perrin

Re: ErrorDocument from a registry script

am 07.05.2009 20:21:44 von Adam Prime

Michael Peters wrote:
> Michael A. Capone wrote:
>> In the spirit of checking off the obvious things... are you sure that
>> the ErrorDocument directive is working for other pages? in other
>> words, can you open a browser and goto
>> http://mydomain.com/this_file_does_not_exist.htm and see your
>> ErrorDocument?\
>
> Yes, that's how I know that it's not the browser silently ignoring my
> ErrorDocument (which IE is known to do).
>
> Has anyone else done this before or can someone confirm to me that it
> should work? Would help to know that I'm not chasing an impossible dream.
>

I don't have a mod_perl 1.3 setup handy, but i was able to get it to do
what you're wanting to do just fine in mod_perl 2

--- httpd.conf

ErrorDocument 404 /404.html

Alias /perl/ /usr/local/prefork/perl/

SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all


--- registry script:

use strict;
use warnings;

use Apache2::Const qw(:common);

my $r = shift;

$r->status(NOT_FOUND);

---

requesting the script results in me seeing the error document found at
/404.html

Adam

Re: ErrorDocument from a registry script

am 07.05.2009 20:51:23 von mpeters

Perrin Harkins wrote:

> You also need to return the correct code from the handler. This is
> not simple to do from Registry. Have a quick look at the list
> archives for things related to Registry and 304/404 handling.
>
> Apache::RedirectLogFix might be the ticket for you.

I'd rather not have to go that route if possible, just seems a little messy for
this one small problem (and it seems that A::RLF doesn't return anything but OK
so it's not apparent that returning NOT_FOUND would really work there).

Looking at this email thread
(http://perl.markmail.org/message/yimclxzgspjtibbn?q=Apache: :Registry+404+ErrorDocument#query:Apache%3A%3ARegistry
404 ErrorDocument+page:1+mid:xtfrl2hywqugoqlh+state:results) it seems that it
worked (mostly for Mark Stosberg) so there's a glimmer of hope.

--
Michael Peters
Plus Three, LP

Re: ErrorDocument from a registry script

am 07.05.2009 20:54:09 von mpeters

Adam Prime wrote:

> I don't have a mod_perl 1.3 setup handy, but i was able to get it to do
> what you're wanting to do just fine in mod_perl 2

> requesting the script results in me seeing the error document found at
> /404.html

Maybe it's a mod_perl 1.3 limitation. I do get Apache's internal 404 document
(not the browser's) just not my custom ErrorDocument. The HTTP status header is
also the same between the requests.

--
Michael Peters
Plus Three, LP

Re: ErrorDocument from a registry script

am 07.05.2009 21:05:06 von Perrin Harkins

On Thu, May 7, 2009 at 2:51 PM, Michael Peters wrote:
> Looking at this email thread
> (http://perl.markmail.org/message/yimclxzgspjtibbn?q=Apache: :Registry+404+ErrorDocument#query:Apache%3A%3ARegistry
> 404 ErrorDocument+page:1+mid:xtfrl2hywqugoqlh+state:results) it seems that
> it worked (mostly for Mark Stosberg) so there's a glimmer of hope.

Really? It looks to me like he never got it working. The version in
mp 2 addresses this problem, but I don't think it works in mp 1
without hacking Registry a bit.

- Perrin

Re: ErrorDocument from a registry script

am 07.05.2009 21:05:27 von mpeters

Perrin Harkins wrote:

> Really? It looks to me like he never got it working.

He said:

If I just set "status => 404" with CGI.pm / Apache::Registry and return
nothing, it works the first time, and then after that I get a lot of these
errors

And further on in the conversation it seemed like those errors he was getting
were unrelated to the 404/ErrorDocument part of it. But I'm wondering if his "it
works" was just Apache sending it's default 404 document and not the one in the
custom ErrorDocument.

--
Michael Peters
Plus Three, LP

Re: ErrorDocument from a registry script

am 10.02.2010 02:55:53 von Mark Stosberg

I revisited the issue of 404 handling in CGI and Apache::Registry today and here's
what I found. For illustration, here's a minimal CGI script which can illustrate the issue:

#!/usr/bin/perl
print "Status: 404\r\nContent-Type: text/html\r\n\r\nHello";

You can review the status codes being returned by accessing the script with LWP:

lwp-request -sS http://server.com/t.cgi | less

What I would like to have happen is for ErrorDocument to be triggered and
deliver the standard 404 page.

When the script runs in CGI, it does cause Apache to return a proper 404 status
code, but is apparently too late to trigger ErrorDocument, so just "Hello" is
printed instead.

When the script runs under Apache::Registry, the 404 status code is also set
correctly, but Apache prints my "Hello" output *and* sends the ErrorDocument
content.

This interplay is mentioned some mod_perl documentation, with the suggestion to
suppress the ErrorDocument content by returning a "200" code later on:

http://search.cpan.org/~gozer/mod_perl-1.31/faq/mod_perl_faq .pod#So_how_do_I_use_mod_perl_in_conjunction_with_ErrorDocum ent?

The good news that it at least that I think there's a way to have 404 handling
code that works in both CGI and Apache::Registry. The method would be to send
our own full HTML page and then suppress the ErrorDocument output under
mod_perl, perhaps using a method like those docs suggest.

It's tempting to considering patching CGI.pm or another toolkit module to
address this: CGI.pm could automatically call $r->status(200); after
$r->send_cgi_headers to suppress ErrorDocument sending. OTOH, there are
probably a number of people that now expect the current behavior, even if it
can result and in the unexpected and undesirable result of having ErrorDocument
content appended to your own content.

Another alternative would be write my own "404" routine that always sets 404,
but returns nothing in mod_perl (so the ErrorDocument is displayed) but returns
the full error document under CGI.

I would love for this be solved at a toolkit level so folks don't have to keep
re-inventing solutions for this.

Have I missed a better way to handle this?

Mark