use strict;
use HTTP::Proxy qw( :log );
use HTTP::Proxy::HeaderFilter::simple;
use CGI::Util qw( unescape );
my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->push_filter(
host => 'groups.yahoo.com',
response => HTTP::Proxy::HeaderFilter::simple->new(
sub {
my ( $self, $headers, $message ) = @_;
my $location;
return
unless ( $location = $headers->header('Location') )
&& $location =~ m!/interrupt\?!;
$self->proxy->log( FILTERS, "YAHOOGROUPS",
"Ad interrupt detected: fetching $location" );
my $r = $self->proxy->agent->simple_request(
HTTP::Request->new(
GET => $location,
$message->request->headers )
);
$location = unescape($location);
$location =~ s|^(http://[^/]*).*done=([^&]*).*$|$1$2|;
$headers->header( Location => $location );
$headers->header( Set_Cookie => $r->header('Set_Cookie') );
$self->proxy->log( FILTERS, "YAHOOGROUPS",
"Set-Cookie: " . $r->header('Set_Cookie') );
}
)
);
$proxy->start;