1use Test::More tests => 2;
2use strict;
3use HTTP::Proxy;
4use HTTP::Proxy::HeaderFilter::simple;
5use t::Utils;
6
7# create the filter
8my $sub = sub {
9    my ( $self, $headers, $message) = @_;
10    $headers->header( X_Foo => 'Bar' );
11};
12
13my $filter = HTTP::Proxy::HeaderFilter::simple->new($sub);
14
15# create the proxy
16my $proxy = HTTP::Proxy->new(
17    port     => 0,
18    max_clients => 0,
19    max_connections  => 2,
20);
21
22# prepare the proxy and server
23$proxy->init;
24$proxy->agent->proxy( http => "" );
25$proxy->push_filter( response => $filter );
26my $url = $proxy->url;
27
28my $server = server_start();
29my $serverurl = $server->url;
30
31# fork the proxy
32my @pids;
33push @pids, fork_proxy($proxy);
34
35# fork the HTTP server
36my $pid = fork;
37die "Unable to fork web server" if not defined $pid;
38
39if ( $pid == 0 ) {
40    server_next($server) for 1 .. 2;
41    exit 0;
42}
43push @pids, $pid;
44
45#
46# check that the correct transformation is applied
47#
48
49# for GET requests
50my $ua = LWP::UserAgent->new();
51$ua->proxy( http => $url );
52my $response = $ua->request( HTTP::Request->new( GET => $serverurl ) );
53is( $response->header( "X-Foo" ), "Bar", "Proxy applied the transformation" );
54
55# for HEAD requests
56$ua = LWP::UserAgent->new();
57$ua->proxy( http => $url );
58$response = $ua->request( HTTP::Request->new( HEAD => $serverurl ) );
59is( $response->header( "X-Foo" ), "Bar", "Proxy applied the transformation" );
60
61# wait for kids
62wait for @pids;
63
64