Tx for your quick reply. The handler is eventually involved, but the result
is weird.
If my handler is :
while ($f->read(my $buffer, BUFF_LEN)) {
$buffer =~ s/\s+/ /g;
$f->print($buffer);
}
than the output is shown in IE as a empty HTML doc.
If my handler includes a split statement, as in :
while ($f->read(my $buffer, 8192)) {
for (split "\n", $buffer) {
s/\s+/ /;
$f->print($_);
}
}
Than the output is garbaged. After digging into it a bit, I realized that
if the input is UTF-8 encoded (google) than it fails. It the input is ascii,
it's ok. Am I facing an encoding problem ? The recent thread
http://www.gossamer-threads.com/archive/mod_perl_C1/modperl_F7/%5Bmp2%5D_OutputFilter_with_UTF-8_characters_P88526
seems to push in that direction, although I see no clear solution. The first
handler (on top of this document) works on pure ascii files. Are there any
workarounds for this ?
Tx for you help once again,
Cheers,
Bruno.
> -----Message d'origine-----
> De : Stas Bekman [mailto:[EMAIL PROTECTED]
> Envoye : mardi 25 novembre 2003 00:55
> A : Bruno Pommerel
> Cc : [EMAIL PROTECTED]
> Objet : Re: Chaining mod_perl handlers with mod_* handlers ?
>
>
> Bruno Pommerel wrote:
> [...]
> > It seems that when one handler gets called, the second one does not get into
> > play. How can I stack the handlers in the correct order ? What pre-requisite
> > must the perl handler comply with ?
>
> That's correct. Your mistake is very simple:
>
> > <Location /google>
> > SetHandler modperl
> ^^^^^^^^^^^^^^^^^^
> > PerlSetVar Filter On
> > PerlOutputFilterHandler FilterGoogle
> > </Location>
>
> Filters have nothing to do with response handlers as the configuration goes.
> And SetHandler sets a response handler. So what you do is setting /google to
> be handled by proxy, but then you override it to be handled by modperl (and
> you don't specify PerlResponseHandler). Neither you need 'PerlSetVar Filter
> On'. Neither you need to load 'Apache::Filter' from httpd.conf - You do miss
> this module in your filter. mp2 filters have nothing to do with mp1's
> Apache::Filter.
>
> All you need is:
>
> <Location /google>
> PerlOutputFilterHandler FilterGoogle
> </Location>
>
> BTW, it was an interesting example, so I've just added a new test that filters
> incoming POST body before it hits the proxy and outgoing reponse body when
> it comes back from proxy.
>
> Also you need to check for mod_access in your config to be complete.
>
> Here are the client and server sides of the test I'm about to commit
>
> # t/filter/both_str_proxy.t
> use strict;
> use warnings FATAL => 'all';
>
> use Apache::Test;
> use Apache::TestRequest;
> use Apache::TestUtil;
>
> plan tests => 1, (have_module('proxy') && have_access);
>
> my $data = join ' ', 'A'..'Z', 0..9;
> my $expected = lc $data; # that's what the input filter does
> $expected =~ s/\s+//g; # that's what the output filter does
> my $location = '/TestFilter__both_str_proxy/foo';
> my $response = POST_BODY $location, content => $data;
> ok t_cmp($expected, $response, "lc input and reverse output filters");
>
>
> #t/filter/TestFilter/both_str_proxy.pm
> package TestFilter::both_str_proxy;
>
> # very similar to TestFilter::both_str_req_add, but the request is
> # proxified. we filter the POSTed body before it goes via the proxy and
> # we filter the response after it returned from the proxy
>
> use strict;
> use warnings FATAL => 'all';
>
> use Apache::RequestRec ();
> use Apache::RequestIO ();
> use Apache::Filter ();
>
> use Apache::TestTrace;
>
> use Apache::Const -compile => qw(OK M_POST);
>
> sub in_filter {
> my $filter = shift;
>
> debug "input filter";
>
> while ($filter->read(my $buffer, 1024)) {
> $filter->print(lc $buffer);
> }
>
> Apache::OK;
> }
>
> sub out_filter {
> my $filter = shift;
>
> debug "output filter";
>
> while ($filter->read(my $buffer, 1024)) {
> $buffer =~ s/\s+//g;
> $filter->print($buffer);
> }
>
> Apache::OK;
> }
>
> sub handler {
> my $r = shift;
>
> debug "response handler";
>
> $r->content_type('text/plain');
>
> if ($r->method_number == Apache::M_POST) {
> $r->print(ModPerl::Test::read_post($r));
> }
>
> return Apache::OK;
> }
>
> 1;
> __DATA__
> <NoAutoConfig>
> <IfModule mod_proxy.c>
> <IfModule mod_access.c>
> <Proxy http://@servername@:@port@/*>
> Order Deny,Allow
> Deny from all
> Allow from @servername@
> </Proxy>
> ProxyRequests Off
> RewriteEngine On
>
> ProxyPass /TestFilter__both_str_proxy/ \
> http://@servername@:@port@/TestFilter__both_str_proxy_content/
> ProxyPassReverse /TestFilter__both_str_proxy/ \
> http://@servername@:@port@/TestFilter__both_str_proxy_content/
> </IfModule>
> </IfModule>
>
> PerlModule TestFilter::both_str_proxy
> <Location /TestFilter__both_str_proxy>
> PerlInputFilterHandler TestFilter::both_str_proxy::in_filter
> PerlOutputFilterHandler TestFilter::both_str_proxy::out_filter
> </Location>
> <Location /TestFilter__both_str_proxy_content>
> SetHandler modperl
> PerlResponseHandler TestFilter::both_str_proxy
> </Location>
> </NoAutoConfig>
>
>
> __________________________________________________________________
> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org http://ticketmaster.com
>
>
> --
> Reporting bugs: http://perl.apache.org/bugs/
> Mail list info: http://perl.apache.org/maillist/modperl.html
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html