File: yahoogroups.pl

package info (click to toggle)
libhttp-proxy-perl 0.304-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 720 kB
  • sloc: perl: 2,576; makefile: 4
file content (46 lines) | stat: -rwxr-xr-x 1,573 bytes parent folder | download | duplicates (9)
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
43
44
45
46
#!/usr/bin/perl -w
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;

            # ads start by redirecting to 'interrupt'
            return
              unless ( $location = $headers->header('Location') )
              && $location =~ m!/interrupt\?!;

            # fetch the ad page (we need the cookie)
            # use a new request to avoid modifying the original one
            $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    # headers are cloned
                )
            );

            # redirect to our original destination
            # which was stored in the 'done' parameter
            # and pass the cookie along
            $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;