1use Test::More tests => 11; 2 3use HTTP::Proxy; 4use HTTP::Proxy::HeaderFilter; 5use HTTP::Proxy::BodyFilter; 6 7my $stack; 8my $hf = [ sub { 1 }, HTTP::Proxy::HeaderFilter->new() ]; 9my $hf2 = [ sub { 1 }, HTTP::Proxy::HeaderFilter->new() ]; 10my $bf = [ sub { 1 }, HTTP::Proxy::BodyFilter->new() ]; 11 12# test general stack workings 13$stack = HTTP::Proxy::FilterStack->new(); 14 15# all, push 16is_deeply( [ $stack->all ], [], "FilterStack is empty" ); 17$stack->push($hf); 18is_deeply( [ $stack->all ], [ $hf ], "FilterStack has one element" ); 19$stack->push($hf2, $hf); 20is_deeply( [ $stack->all ], [ $hf, $hf2, $hf ], "FilterStack has three elements" ); 21 22# insert 23$stack->insert(1, $hf2); 24is_deeply( [ $stack->all ], [ $hf, $hf2, $hf2, $hf ], "FilterStack is correct"); 25is( scalar $stack->all, 4, "Correct in scalar context too"); 26 27# remove 28my $elem = $stack->remove(1); 29is( $elem, $hf2, "Got back what was in the stack"); 30 31# check insertion in header FilterStack 32eval { $stack->push( $bf ); }; 33like( $@, qr/is not a HTTP::Proxy::HeaderFilter/, "Incorrect Filter class" ); 34 35eval { $stack->insert( 0, $bf ); }; 36like( $@, qr/is not a HTTP::Proxy::HeaderFilter/, "Incorrect Filter class" ); 37 38{ 39 package Foo; 40 use base qw( HTTP::Proxy::HeaderFilter ); 41} 42 43my $foo = [ sub { 1 }, Foo->new() ]; 44eval { $stack->push( $foo ); }; 45is( $@, '', "Can push derived Filters" ); 46 47# same test for body FilterStack 48my $bstack = HTTP::Proxy::FilterStack->new(1); 49eval { $bstack->push( $hf ); }; 50like( $@, qr/is not a HTTP::Proxy::BodyFilter/, "Incorrect Filter class" ); 51 52eval { $bstack->insert( 0, $hf ); }; 53like( $@, qr/is not a HTTP::Proxy::BodyFilter/, "Incorrect Filter class" ); 54 55# current 56# filter 57# filter_last 58 59