You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Benoit Plessis <b....@doyousoft.com> on 2007/02/22 19:00:27 UTC
Error intercept.
Hi,
I'm trying to build an filter that will parse the output of
some application server (AKA the blackbox) and replace the errors messages
with something neater.
For that purpose i installed the following OutputFilter on the
reverse-proxy:
---8<----------------
package MyApache2::FilterColdfusion;
use base qw(Apache2::Filter);
use strict;
use warnings FATAL => 'all', NONFATAL => 'redefine';
use Apache2::Filter ();
use Apache2::RequestRec ();
use Apache2::Log;
use APR::Table ();
use Apache2::Reload;
use Apache2::Const -compile => qw(OK DECLINED :log);
use APR::Const -compile => qw(:error SUCCESS);
my $error_page;
BEGIN {
# Load the generic response text:
local $/;
undef $/;
open IN, "</etc/apache2/cferror.html";
$error_page = <IN>;
}
sub handler { #: FilterRequestHandler FilterHasInitHandler(\&init) {
my $f = shift;
my $r = $f->r;
# Filter only generated text
if (($r->status() < 300) &&
$r->content_type() =~ /text\/html/) {
if (!$f->ctx()) {
# Test: randomly intercept:
$f->ctx ({intercept => int(rand() + .5)});
if ($f->ctx->{intercept}) {
$r->headers_out->unset('Content-Length');
# Record matched error
$r -> log_reason ("Intercepted Coldfusion
Error",$r->filename);
# print Error generic message
$f -> print ($error_page);
$r -> headers_out->set('Content-Length', length
$error_page);
# exit with OK
return Apache2::Const::OK;
}
} else {
if ($f->ctx->{intercept}) {
$r -> log_reason ("Intercepted since previously set to",
$r->filename);
return Apache2::Const::OK;
}
}
}
# Not an error => let mod_perl copy the text
return Apache2::Const::DECLINED;
}
1;
---8<----------------
When using wget -SO - http://url/ things seem to be ok, i got the want
text, and
headers seems good to me:
HTTP/1.1 200 OK
Date: Thu, 22 Feb 2007 17:53:52 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) AuthMySQL/4.3.9-2 mod_perl/1.29
Page-Completion-Status: Normal
Page-Completion-Status: Normal
Content-Type: text/html; charset=iso-8859-1
Content-Length: 2048
Vary: Accept-Encoding
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
<html>
<head>
<title>Incident sur l'hebergement</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.....
Using links everything goes fine, but firefox do not show anything (and
there is nothing in 'view source').
(Well if the rand() did not trigger then in this case Firefox show the
proxy'ed content correctly).
Any idea ? something i did wrong ?
Regards
--
Benoit Plessis
Re: Error intercept.
Posted by Benoit Plessis <b....@doyousoft.com>.
Robert Landrum wrote:
> Given that this is in French, is it possible this is a UTF8 issue?
> Could length $error_page be returning a value that is inconsistent
> with the actual length of the message. If so, firefox might be
> ignoring some or all of the message.
>
> I could be wrong. I would try unsetting content length to see if that
> corrects the issue.
In fact i did set content-length for the exact same reason, but there is
no change in either case.
Well if the content length is not exact links did cut the output, but as
for FF, nothing changed
Thanks for the reply anyway,
--
Benoit
Re: Error intercept.
Posted by Robert Landrum <rl...@aol.net>.
Benoit Plessis wrote:
> $r -> headers_out->set('Content-Length', length
> $error_page);
>
Hmm...
> <html>
> <head>
> <title>Incident sur l'hebergement</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <style type="text/css">
> .....
>
> Using links everything goes fine, but firefox do not show anything (and
> there is nothing in 'view source').
> (Well if the rand() did not trigger then in this case Firefox show the
> proxy'ed content correctly).
>
> Any idea ? something i did wrong ?
Given that this is in French, is it possible this is a UTF8 issue?
Could length $error_page be returning a value that is inconsistent with
the actual length of the message. If so, firefox might be ignoring some
or all of the message.
I could be wrong. I would try unsetting content length to see if that
corrects the issue.
Rob
Re: Error intercept.
Posted by Benoit Plessis <b....@doyousoft.com>.
Benoit Plessis a écrit :
> Perrin Harkins a écrit :
>> On 2/22/07, Benoit Plessis <b....@doyousoft.com> wrote:
>>> When using wget -SO - http://url/ things seem to be ok, i got the want
>>> text, and
>>> headers seems good to me:
>> [...]
>>> Using links everything goes fine, but firefox do not show anything
>>> (and
>>> there is nothing in 'view source').
>>
>> Why don't you compare the text of the requests these clients are
>> sending and figure out which header or change makes it stop working?
>>
>> - Perrin
>
> Hell yes, i don't know why i focused on the script, it must be that
> mod_deflate isn't triggered
> by wget/links while it is by firefox.
> And there is many chances that it is triggered before my script.
>
> Thanks, i'll look into it.
>
Well, it was linked to mod_deflate in all ways.
It migrated to the bucket brigade interface and deflate seem to like
much more.
Thanks
--
Benoit Plessis +33 4 67 36 42 59
<b....@doyousoft.com>
Ingénieur Réseau
Responsable Infrastructure Système & Réseau.
do|you|soft
Re: Error intercept.
Posted by Benoit Plessis <b....@doyousoft.com>.
Perrin Harkins a écrit :
> On 2/22/07, Benoit Plessis <b....@doyousoft.com> wrote:
>> When using wget -SO - http://url/ things seem to be ok, i got the want
>> text, and
>> headers seems good to me:
> [...]
>> Using links everything goes fine, but firefox do not show anything (and
>> there is nothing in 'view source').
>
> Why don't you compare the text of the requests these clients are
> sending and figure out which header or change makes it stop working?
>
> - Perrin
Hell yes, i don't know why i focused on the script, it must be that
mod_deflate isn't triggered
by wget/links while it is by firefox.
And there is many chances that it is triggered before my script.
Thanks, i'll look into it.
--
Benoit Plessis +33 4 67 36 42 59
<b....@doyousoft.com>
Ingénieur Réseau
Responsable Infrastructure Système & Réseau.
do|you|soft
Re: Error intercept.
Posted by Perrin Harkins <ph...@gmail.com>.
On 2/22/07, Benoit Plessis <b....@doyousoft.com> wrote:
> When using wget -SO - http://url/ things seem to be ok, i got the want
> text, and
> headers seems good to me:
[...]
> Using links everything goes fine, but firefox do not show anything (and
> there is nothing in 'view source').
Why don't you compare the text of the requests these clients are
sending and figure out which header or change makes it stop working?
- Perrin