use Test::More tests => 4;
use HTTP::Proxy;
use HTTP::Proxy::BodyFilter::tags;
use HTTP::Proxy::BodyFilter::htmltext;
use t::Utils;
use strict;
# a very simple proxy
my $proxy = HTTP::Proxy->new( port => 0 );
$proxy->push_filter(
mime => 'text/html',
response => HTTP::Proxy::BodyFilter::tags->new,
response => HTTP::Proxy::BodyFilter::htmltext->new(
sub { tr/a-zA-z/n-za-mN-ZA-M/ }
)
);
# get and test the filter stack
my $stack = $proxy->_filter_stack(
body => 'response',
HTTP::Request->new( GET => 'http://foo.com/bar.html' ),
HTTP::Response->new(
200, "OK", HTTP::Headers->new( 'Content-Type' => 'text/html' )
)
);
for (
[ "abc", "nop" ],
[ "100 € is expensive", "100 € vf rkcrafvir" ],
[ " <-- here ", " <-- urer " ],
[
qq'\n foo',
qq'\n sbb',
],
)
{
my $data = "$_->[0]";
$stack->select_filters( $proxy->{response} );
$stack->filter( \$data, $proxy->{response}, undef );
is( $data, $_->[1], "Correct data transformation" );
}