output filters

output filters

am 31.01.2008 15:17:29 von J Amuse

------=_Part_23813_24590177.1201789049895
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I'm trying to write a filter using modperl that will update parts of the
server response on the fly. My first attempt was to rewrite the path setting
in the server's set cookie response to set the path to: path=/NewPath. After
copying and pasting some examples I came up with the following:
package Apache2::RewriteCookiePath;
use strict;
use warnings;
use Apache2::Filter ();
use Apache2::RequestRec ();
use APR::Table ();
use Apache2::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;

sub handler {
my $f = shift;

while ($f->read(my $buffer, BUFF_LEN)) {
$buffer =~ s/path=\//path=\/NewPath/g;
$f->print($buffer);
}

return Apache2::Const::OK;
}
1;

I have not been able to get this code to work. How can I call this code from
a virtual host's config file so that it applies to all cookies set, no
matter what subdirectory is requested? This is my first attempt with
mod-perl, so any pointers would be really helpful.

Thanks

------=_Part_23813_24590177.1201789049895
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I'm trying to write a filter using modperl that will update parts of the server response on the fly. My first attempt was to rewrite the path setting in the server's set cookie response to set the path to: path=/NewPath. After copying and pasting some examples I came up with the following:

package Apache2::RewriteCookiePath;
use strict;
use warnings;
use Apache2::Filter ();
use Apache2::RequestRec ();
use APR::Table ();
use Apache2::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;


sub handler {
my $f = shift;

while ($f->read(my $buffer, BUFF_LEN)) {
   $buffer =~ s/path=\//path=\/NewPath/g;
   $f->print($buffer);
}

return Apache2::Const::OK;
}
1;

I have not been able to get this code to work. How can I call this code from a virtual host's config file so that it applies to all cookies set, no matter what subdirectory is requested? This is my first attempt with mod-perl, so any pointers would be really helpful.


Thanks



------=_Part_23813_24590177.1201789049895--

RE: output filters

am 31.01.2008 16:32:30 von Adam Prime x443

If you're using the stream API like this you'll never see the headers in
$buffer. =20

I think you would have to modify them using $f->r (the request object),
then abuse the headers_out and/or err_headers_out tables.

I'm not sure if this is the case for the bucket brigade API or not (i've
never used it)

You should also note that if you were going to run a regexp like that
you'd need to handle the cases where the token you were trying to
substitute was split by a read.

You can take a look at Apache2::Filter::TagAware on CPAN, which was
built based on a talk that Geoff Young gave a couple years ago at
ApacheCon. his slides are here:=20
http://www.modperlcookbook.org/~geoff/slides/ApacheCon/2006/ mp2_filters-
printable.pdf.gz

There are also some other Filter's on CPAN you could take a look at.
http://search.cpan.org/search?query=3DApache2%3A%3AFilter&mo de=3Dall

Adam

-----Original Message-----
From: J Amuse [mailto:jamuse@gmail.com]=20
Sent: Thursday, January 31, 2008 9:17 AM
To: modperl@perl.apache.org
Subject: output filters

I'm trying to write a filter using modperl that will update parts of the
server response on the fly. My first attempt was to rewrite the path
setting in the server's set cookie response to set the path to:
path=3D/NewPath. After copying and pasting some examples I came up with
the following:
package Apache2::RewriteCookiePath;
use strict;
use warnings;
use Apache2::Filter ();
use Apache2::RequestRec ();
use APR::Table ();
use Apache2::Const -compile =3D> qw(OK);
use constant BUFF_LEN =3D> 1024;

sub handler {
my $f =3D shift;

while ($f->read(my $buffer, BUFF_LEN)) {
$buffer =3D~ s/path=3D\//path=3D\/NewPath/g;
$f->print($buffer);
}

return Apache2::Const::OK;
}
1;

I have not been able to get this code to work. How can I call this code
from a virtual host's config file so that it applies to all cookies set,
no matter what subdirectory is requested? This is my first attempt with
mod-perl, so any pointers would be really helpful.

Thanks