Created
December 3, 2015 08:42
-
-
Save tofuseng/1fb9e2ef30933166bfcf to your computer and use it in GitHub Desktop.
wvs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Mojo::UserAgent; | |
use Mojo::Server::Daemon; | |
use Bloom::Filter; | |
my $bloom_filter = Bloom::Filter->new( error_rate => 0.001, capacity => 100000 ); | |
my $ua = Mojo::UserAgent->new; | |
my $daemon = Mojo::Server::Daemon->new( listen => ['http://*:3128'])->unsubscribe('request'); | |
$daemon->on(request => sub { | |
my ($daemon, $client_tx) = @_; | |
$ua->start(Mojo::Transaction::HTTP->new(req => $client_tx->req) => sub { | |
my ($ua, $proxy_tx) = @_; | |
my $response = $proxy_tx->res; | |
$client_tx->res($response)->resume; | |
my $url = $proxy_tx->req->url->to_string; | |
if( $url =~ /jsonp|callback/ || defined($response->headers->content_type) && $response->headers->content_type =~ /json/) { | |
my $json = $response->text; | |
if( ! $bloom_filter->check($url.$json) ) { | |
$bloom_filter->add($url.$json); | |
print "$url\n$json\n\n"; | |
} | |
} | |
}); | |
}); | |
$daemon->run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment