File Coverage

blib/lib/App/HTTP_Proxy_IMP/IMP/Example/changeTarget.pm
Criterion Covered Total %
statement 16 25 64.0
branch 0 2 0.0
condition n/a
subroutine 6 12 50.0
pod 6 7 85.7
total 28 46 60.8


line stmt bran cond sub pod time code
1             # sample IMP plugin to change target host by replacing request header
2             # for this example it get changed to spiegel.de - whatever we want to access
3             # THIS IS JUST A SILLY EXAMPLE!!!!
4              
5 1     1   7 use strict;
  1         2  
  1         33  
6 1     1   5 use warnings;
  1         2  
  1         37  
7             package App::HTTP_Proxy_IMP::IMP::Example::changeTarget;
8 1     1   5 use base 'Net::IMP::HTTP::Request';
  1         2  
  1         528  
9              
10 1     1   3861 use Net::IMP;
  1         2  
  1         79  
11 1     1   7 use Net::IMP::Debug;
  1         2  
  1         4  
12              
13             my $target = 'www.spiegel.de';
14 1     1 0 12 sub RTYPES { ( IMP_PASS,IMP_REPLACE,IMP_DENY ) }
15              
16             sub new_analyzer {
17 0     0 1   my ($class,%args) = @_;
18 0           my $self = $class->SUPER::new_analyzer(%args);
19 0           $self->run_callback(
20             # we don't need to look at response
21             [ IMP_PASS,1,IMP_MAXOFFSET ],
22             );
23 0           return $self;
24             }
25              
26              
27             sub request_hdr {
28 0     0 1   my ($self,$hdr) = @_;
29 0 0         my $len = length($hdr) or return;
30 0           $hdr =~s{\A(\S+\s+http://)([^\s/]+)}{$1$target}; # first line absoluteURI
31 0           $hdr =~s{^Host:\s*(.*)}{Host: www.spiegel.de}mi; # host header
32 0           $self->run_callback(
33             [ IMP_REPLACE,0,$len,$hdr ], # replace header
34             [ IMP_PASS,0,IMP_MAXOFFSET ], # pass thru everything else
35             );
36             }
37              
38             # will not be called
39       0 1   sub request_body {}
40       0 1   sub response_hdr {}
41       0 1   sub response_body {}
42       0 1   sub any_data {}
43              
44             1;
45              
46             __END__