1use strict; 2use Test::More; 3use HTTP::Proxy; 4use HTTP::Proxy::BodyFilter::tags; 5use HTTP::Proxy::BodyFilter::simple; 6use HTTP::Proxy::BodyFilter::complete; 7use HTTP::Proxy::BodyFilter::htmltext; 8use HTTP::Proxy::BodyFilter::lines; 9use HTTP::Proxy::BodyFilter::save; 10use HTTP::Request; 11 12my @idem_filters = qw( complete lines save tags ); 13 14plan tests => 2 + @idem_filters; 15 16my $proxy = HTTP::Proxy->new( port => 0 ); 17 18my $req = HTTP::Request->new( GET => 'http://www.vronk.com/' ); 19my $res = HTTP::Response->new( 200 ); 20$res->request( $req ); 21$res->content_type( 'text/html' ); 22$proxy->request( $req ); 23$proxy->response( $res ); 24 25# basic values 26for my $filter (@idem_filters) { 27 $req->uri("http://www.$filter.com/"); 28 $proxy->push_filter( 29 response => "HTTP::Proxy::BodyFilter::$filter"->new ); 30 31 $proxy->{body}{response}->select_filters($res); 32 is( $proxy->{body}{response}->will_modify($res), 33 0, qq{Filter $filter won't change a thing} ); 34} 35 36 37# change the request info 38$req->uri( 'http://www.zlonk.com/' ); 39 40# filters that don't modify anything 41$proxy->push_filter( 42 host => 'zlonk.com', 43 response => HTTP::Proxy::BodyFilter::tags->new(), 44 response => HTTP::Proxy::BodyFilter::complete->new(), 45); 46 47$proxy->{body}{response}->select_filters( $res ); 48ok( !$proxy->{body}{response}->will_modify(), 49 q{Filters won't change a thing} 50); 51 52# simulate end of connection 53$proxy->{body}{response}->eod(); 54 55# add a filter that will change stuff 56$proxy->push_filter( 57 host => 'zlonk.com', 58 response => HTTP::Proxy::BodyFilter::simple->new( sub {} ), 59); 60 61$proxy->{body}{response}->select_filters( $res ); 62ok( $proxy->{body}{response}->will_modify( $res ), 63 q{Filters admit they will change something} 64); 65 66unlink( 'www.zlonk.com' ); # cleanup file created by HPBF::save 67