|
Hi,
I'm currently using Apache v2.0.54, with MP 2.0.2
and Mason 1.32, all that under
Win32.
The purpose for me is to handle a request, and,
whenever an error happens (thrown with die), I want to show a standard page to
the user (let's call it error.html).
I'm using a custom handler.
I found 2 ways of doing it:
**********
Method1: using an external redirect:
In the component itself (an html page), using an
eval:
use Apache2::Const qw(:http);
eval{
print q{<h1>Hello</h1>}; die "groin"; }; if ($@){ ${$r->headers_out}{Location} = "error/500.html"; $r->status( HTTP_MOVED_TEMPORARILY ) ; $r->pnotes( error => $@
);
return; } Here, the browser URL changes to
/error.html.
**********
Method2: Handling my request within an eval block,
in the request handler, for example:
sub handler{
my $r = shift; my $return = eval {
$ah->handle_request($r) };
if ( my $err = $@ )
{ $r->pnotes( error => $err ); $r->filename( $r->document_root . '/error.html' ); return
$ah->handle_request($r);
} return $return;
}
Here, the client browser doesn't even know that
something happened (the URL stays the same): the error flow is added to
the regular flow. In order to trigger error.html, I just have to die within
my component. Both these methods are working well, and from the
client browser point of view, method1 is transparent (no redirection) while
method2 changes the browser URL (external redirect).
But my problem is here: for some lenghty pages, I
prefer sometimes to flush the buffer ($m->flush_buffer or $r->rflush),so
that the user doesn't have to wait for the whole page to be generated, before
seeing something.
But if the buffer is flushed before the die
happens, a problem happens:
- For method1, some content (ie the content
generated by the component before the flush call happens) is shown,
directly followed by the error content. This is messy.
- For method2, if the content is flushed before the
die, then, the redirection doesn't work at all.
I perfectly understand why that for both
methods.
But I'm wondering if there's a way for me to
circumvent that, ie to make my component generate and flush content as needed,
but, if an error happens, to force the browser to go to my error page, with the
already sent content disapearing from screen?
I hope I made myself clear.
Thanks,
Lionel.
|
- [Mason] Forcing redirection after some content has been flus... Lionel MARTIN
- Re: [Mason] Forcing redirection after some content has ... Jeremy Blain
- Re: [Mason] Forcing redirection after some content ... Lionel MARTIN
- Re: [Mason] Forcing redirection after some cont... RJ Herrick
- Re: [Mason] Forcing redirection after some ... Lionel MARTIN

