| 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 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 6 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 7 |  |  |  |  |  |  | package App::HTTP_Proxy_IMP::IMP::Example::changeTarget; | 
| 8 | 1 |  |  | 1 |  | 5 | use base 'Net::IMP::HTTP::Request'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 805 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 1 |  |  | 1 |  | 4084 | use Net::IMP; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 97 |  | 
| 11 | 1 |  |  | 1 |  | 5 | use Net::IMP::Debug; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 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__ |