1use Test::More tests => 4;
2use HTTP::Proxy;
3use HTTP::Proxy::BodyFilter::tags;
4use HTTP::Proxy::BodyFilter::htmltext;
5use t::Utils;
6use strict;
7
8# a very simple proxy
9my $proxy = HTTP::Proxy->new( port => 0 );
10
11$proxy->push_filter(
12    mime     => 'text/html',
13    response => HTTP::Proxy::BodyFilter::tags->new,
14    response => HTTP::Proxy::BodyFilter::htmltext->new(
15        sub { tr/a-zA-z/n-za-mN-ZA-M/ }
16    )
17);
18
19# get and test the filter stack
20my $stack = $proxy->_filter_stack(
21    body => 'response',
22    HTTP::Request->new( GET => 'http://foo.com/bar.html' ),
23    HTTP::Response->new(
24        200, "OK", HTTP::Headers->new( 'Content-Type' => 'text/html' )
25    )
26);
27
28for (
29    [ "<b>abc</b>",                     "<b>nop</b>" ],
30    [ "<b>100</b> &euro; is expensive", "<b>100</b> &euro; vf rkcrafvir" ],
31    [ "</b> <-- here </b>",             "</b> <-- urer </b>" ],
32    [
33qq'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//FR" "http://www.w3.org/TR/html4/loose.dtd"\n<style><!--\nbody,td,a,p{font-family:arial;}\n//-->\n</style> foo',
34qq'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//FR" "http://www.w3.org/TR/html4/loose.dtd"\n<style><!--\nbody,td,a,p{font-family:arial;}\n//-->\n</style> sbb',
35    ],
36  )
37{
38    my $data = "$_->[0]";
39    $stack->select_filters( $proxy->{response} );
40    $stack->filter( \$data, $proxy->{response}, undef );
41    is( $data, $_->[1], "Correct data transformation" );
42}
43
44