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