I am trying to write a proxy that will only proxy a preset list of URLs (for my kids). Can I do that with Http::Proxy? For some reason, I cannot wrap my brain around how...
#!perl use HTTP::Proxy; my $port=8080; # initialisation my $proxy = HTTP::Proxy->new( port => $port ); # this is a MainLoop-like method print "Running proxy on port $port\n"; $proxy->start;
UPDATE: Thanks for all the replies but, with the exception of tirwhan , no one really seemed to want to answer my question. I guess it is much funner to advise me on my parenting skills. Anyway, for anyone else who might be looking.. Here is the finished code..
#!perl use strict; use HTTP::Proxy; use HTTP::Proxy::Engine; use HTTP::Proxy::Engine::NoFork; use HTTP::Proxy::HeaderFilter::simple; my $port=8080; my %Allowed=( 'pbskids.org' => 1, 'www.basgetti.com' => 1, 'disney.com' => 1, ); my $proxy = HTTP::Proxy->new( port => $port ); $proxy->push_filter ( request => HTTP::Proxy::HeaderFilter::simple->new( sub { my ($self, $headers, $message) = @_; my $host=$headers->{host}; $host=lc(strip($host)); my $uhost=getUniqueHost($host); $uhost=lc(strip($uhost)); my $allow=$Allowed{$host} || $Allowed{$uhost} || 0; if(!$allow && $host !~/localhost$/is){ print "$host not allowed\n"; $headers->{host} = "localhost"; $headers->{cookie} = ''; } }) ); print "Running proxy on port $port\n"; $proxy->start; ######################### sub getUniqueHost{ my $inhost=shift || return; my $uhost; if($inhost=~/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/){$uhost=$inhost;} elsif($inhost=~/([A-Z0-9\-]+)\.([A-Z0-9\-]+)\.([A-Z0-9\-]+)/is){$u +host=$2 . '.' . $3;} else{$uhost=$inhost;} $uhost=lc($uhost); return $uhost; } ############### sub strip{ my $str=shift; if(length($str)==0){return;} $str=~s/^[\r\n\s\t]+//s; $str=~s/[\r\n\s\t]+$//s; return $str; }

-------------------------------
by me
http://www.basgetti.com
http://www.kidlins.com


In reply to Can I use Http::Proxy to intercept and deny URLs? by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.