1#!/usr/bin/perl -w
2use strict;
3use HTTP::Proxy qw( :log );
4use HTTP::Proxy::HeaderFilter::simple;
5use vars qw( $re );
6
7# this is a very simple ad blocker
8# a full-fledged ad blocker should be a module
9
10# this dot is *not* a web bug ;-)
11my $no = HTTP::Response->new( 200 );
12$no->content_type('text/plain');
13$no->content('.');
14
15my $filter = HTTP::Proxy::HeaderFilter::simple->new( sub {
16   my ( $self, $headers, $message ) = @_;
17   $self->proxy->response( $no ) if $message->uri->host =~ /$re/o;
18} );
19
20my $proxy = HTTP::Proxy->new( @ARGV );
21$proxy->push_filter( request => $filter );
22$proxy->start;
23
24# a short and basic list
25BEGIN {
26    $re = join '|', map { quotemeta } qw(
27        ads.wanadooregie.com
28        cybermonitor.com
29        doubleclick.com
30        adfu.blockstackers.com
31        bannerswap.com
32        click2net.com
33        clickxchange.com
34        dimeclicks.com
35        fastclick.net
36        mediacharger.com
37        mediaplex.com
38        myaffiliateprogram.com
39        netads.hotwired.com
40        valueclick.com
41    );
42}
43
44