File: 42will_modify.t

package info (click to toggle)
libhttp-proxy-perl 0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 492 kB
  • ctags: 126
  • sloc: perl: 2,313; makefile: 40
file content (42 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use Test::More tests => 2;
use HTTP::Proxy;
use HTTP::Proxy::BodyFilter::tags;
use HTTP::Proxy::BodyFilter::simple;
use HTTP::Proxy::BodyFilter::complete;
use HTTP::Request;

my $proxy = HTTP::Proxy->new( port => 0 );

my $req = HTTP::Request->new( GET => 'http://www.zlonk.com/' );
my $res = HTTP::Response->new();
$res->request( $req );
$res->content_type( 'text/html' );
$proxy->request( $req );
$proxy->response( $res );

# filters that don't modify anything
$proxy->push_filter(
    host     => 'zlonk.com',
    response => HTTP::Proxy::BodyFilter::tags->new(),
    response => HTTP::Proxy::BodyFilter::complete->new(),
);

$proxy->{body}{response}->select_filters( $res );
ok( !$proxy->{body}{response}->will_modify(),
    q{Filters won't change a thing}
);

# simulate end of connection
$proxy->{body}{response}->eod();

# add a filter that will change stuff
$proxy->push_filter(
    host     => 'zlonk.com',
    response => HTTP::Proxy::BodyFilter::simple->new( sub {} ),
);

$proxy->{body}{response}->select_filters( $res );
ok( $proxy->{body}{response}->will_modify( $res ),
    q{Filters admit they will change something}
);