File: adblock.pl

package info (click to toggle)
libhttp-proxy-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 568 kB
  • sloc: perl: 2,392; makefile: 2
file content (43 lines) | stat: -rwxr-xr-x 1,036 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/perl -w
use strict;
use HTTP::Proxy qw( :log );
use HTTP::Proxy::HeaderFilter::simple;
use vars qw( $re );

# this is a very simple ad blocker
# a full-fledged ad blocker should be a module

# this dot is *not* a web bug ;-)
my $no = HTTP::Response->new( 200 );
$no->content_type('text/plain');
$no->content('.');

my $filter = HTTP::Proxy::HeaderFilter::simple->new( sub {
   my ( $self, $headers, $message ) = @_;
   $self->proxy->response( $no ) if $message->uri->host =~ /$re/o;
} );

my $proxy = HTTP::Proxy->new( @ARGV );
$proxy->push_filter( request => $filter );
$proxy->start;

# a short and basic list
BEGIN {
    $re = join '|', map { quotemeta } qw(
        ads.wanadooregie.com
        cybermonitor.com
        doubleclick.com
        adfu.blockstackers.com
        bannerswap.com
        click2net.com
        clickxchange.com
        dimeclicks.com
        fastclick.net
        mediacharger.com
        mediaplex.com
        myaffiliateprogram.com
        netads.hotwired.com
        valueclick.com
    );
}